Saturday, January 28, 2012

Experiments with JavaFx 2.0 (Part 1)

Playing around with JavaFx 2.0. It surely looks interesting and a great relief for desktop application developers. UI is promising. For displaying a browser inside your application,
" WebView view = new WebView(); view.getEngine().load("http://satkk.blogspot.com"); "
Add the web view to the scene and run the application. More advanced stuff is available in http://docs.oracle.com/javafx/2.0/webview/jfxpub-webview.htm
public class WebEngine extends Application {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
    
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Hello World!");
        Group root = new Group();
        WebView view = new WebView();
        view.getEngine().load("http://satkk.blogspot.com");
       
        Scene scene = new Scene(view);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

Tuesday, January 24, 2012

Enable JavaFx 2 for linux on Netbeans 7.1

For those who installed Netbeans 7.1 with JDK7 earlier and now downloaded javafx sdk for linux, it might be a showstopper for a while especially when trying to create a new javafx application. Tip: Go to Netbeans platform and add java platforms, point out to jdk 7, and watch out for enable javafx tab. Point out your javafx sdk and start javafxing :)

Friday, December 9, 2011

Enable Netbeans Autocompletion(Similar to Intellij)

One thing i always envied about Intellij is their smart Autocompletion, BTW this feature is available in Netbeans too..Here is the trick[ Using Netbeans 7 ]

Tools->Options->Editor
In the drop down, select Java, now check the Auto Popup on typing any identifier part..

PS: Can also be annoying at times.

Monday, November 14, 2011

Customizing your Netbeans Look and Feel


To apply Nimbus look and feel to your netbeans ide, you will have to edit netbeans.conf which is found in your netbeans installation directory( etc is the folder name ).

Here is the line where i added lnf options

 netbeans_default_options="--laf com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel -J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=384m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true"

Now restart your ide :) 


Now to your own RCP app, just add
run.args.extra=--laf com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel
to your project.properties

[ This is for development purposes only]
More details : http://wiki.netbeans.org/DevFaqChangeLookAndFeel








Wednesday, September 28, 2011

Oh! MY java.util.ConcurrentModificationException


 It's one of the common exception that occurs when you iterate over a collection and try to remove an entry.

Few examples are:
List<String> list = new ArrayList<String>();
list.add("2);
list.add("3");
list.add("4");
for(String s: list){
   if(s.equals("2")){
      list.remove(s);
   }

} and run the snippet, we can see  Exception in thread "main" java.util.ConcurrentModificationException.

Now just a little modification, we will use Iterator, since it can allow to remove the element while iterating, so the resultant code looks like

 List<String> list = new ArrayList<String>();
 for(Iterator<String> it=list.iterator;it.hasNext();){
    if(it.next().equals("2"){
     it.remove();
}
}

System.out.println("Size of List"+list.size());
Which will give output as 2 :)

-----------------------------------------------------
Now the same for HashMap

Map<String, Integer> map = new HashMap<String, Integer>();
        map.put("122", 233);
        map.put("124", 456);
        map.put("125", 345);
        for (Entry<String, Integer> entry : map.entrySet()) {
            System.out.println(entry.getKey() + "    " + entry.getValue());
        }
        for (Entry<String, Integer> entry : map.entrySet()) {
            if (entry.getKey().equals("125")) {
                map.remove(entry.getKey());
            }
        }
Same exception,
Now modify the loop as
for(Iterator<Entry<String, Integer>> iterator= map.entrySet().iterator();iterator.hasNext();){
            Entry<String, Integer> next = iterator.next();
            if(next.getValue()==456){
                iterator.remove();
            }
        } Its Gone!













Sunday, September 25, 2011

Groovy is fun!


Just played around with a few xml and Groovy( i think it has a very short learning curve, i could follow the code,even though i ve no much experience in it), its first class support to xml is brilliant .

Just
def writer = new StringWriter();
def builder = new MarkupBuilder(writer);
builder.root {
child {
title "Child 1"
}
}
println(writer);  

This is enough to build a small xml file. Parsing is also fun( have tried XmlSlurper). Since they are plain java byte codes after compilation, only an additional groovy library is enough for calling these utilities from our java application.Groovy can be handy if we want to write some fast utility classes(In fact, we can call it as Super Java). Java + Groovy DSL is fun. Now planning to compose a full fledged xml utility class with groovy.