Tuesday, April 8, 2008

Eclipse Project using GUI designed from NetBeans IDE 6.1 Beta

My office uses Eclipse for the main development projects. This was a decision taken in the beginning of the product life cycle and must be maintained for the whole project as the sand boxes and developer documentation release documentation contains references to Eclipse.

When there is a need of decent GUI to be developed my team members face challenge playing with different layout managers and hand coded Java classes. The GUI building mechanism in Eclipse is available for commercial plugins like MyEclipse which we are not willing to use as company policy.

NetBeans IDE 6.1 Beta comes to rescue us from this situation. NetBeans IDE 6.1 Beta can import the Eclipse project as it is and even without shifting the source files. It only creates a configuration folder for the nbproject files and maintains the project in the Eclipse workspace. This provides a facility of working in same code base with Eclipse IDE as well as NetBeans IDE at the same time.

As an example let us see one simple PhoneBook application which I started as a project in Eclipse 3.3 Europa.

I used the Eclipse Project Importer module in NetBeans to import the project by specifying the workspace of the PhoneBook project. (Please refer to earlier post for importing eclipse projects). We can see below the project as seen in the NetBeans IDE.

In NetBeans I started the JFrame wizard by right clicking the package and choosing the
New > JFrame Form option...

NetBeans offered me to type the name of frame which i filled as PhoneBookFrame and clicked Finish to complete the wizard.

NetBeans created JFrame form class for me. NetBeans shows GUI classes with Design as well as source editors and we have facility to use the Matisse GUI designer available in NetBeans.

I designed a decent GUI on the JFrame very quickly by dragging the controls and assigning them appropriate properties in the properties window. NetBeans created appropriate code in the PhoneBookFrame.java class for me automatically.

Then I copied the code inside the main method of the JFrame auto-generated class to my main method in PhoneBookDemo.java main class and ran the project to see the application GUI.

The real magic starts now when I came back to my Eclipse editor. I refreshed the project and could see the newly created PhoneBookFrame.java class in the project file list. There is no error shown this proves that NetBeans does not use any custom package not available in Java distribution. Even if use the Matisse GUI designer the code emitted is using standard Java packages and classes.

So when I executed the code in Eclipse it also showed the same GUI. Wow! this is too good. Now I do not have any problem designing GUI even in my Eclipse projects.

I just have to import the project in NetBeans and design and generate the GUI classes through the goodness of NetBeans Matisse designer and then I can continue development even in the Eclipse editor for the rest of the project.

I think NetBeans has done a great job in providing the Eclipse Project Importer and especially the feature of working simultaneously keeping the workspace and the source code at the same place. This way I can assign the GUI design to one team member who will work on NetBeans only and handle all the GUI designing tasks and rest of the team can continue in routine tasks of calling the GUI classes.

This will also provide my team members exposure to NetBeans IDE even if they work on Eclipse as their main development IDE. Who knows for the next project we may opt for NetBeans IDE altogether.

with regards
Tushar Joshi, Nagpur


  1. You can also mention that if you are using older version of Java (1.5 or less) you must import swing-layout.jar library (Group Layout support) that is located in [NB-dir]/platform8/modules/ext directory.

  2. andon has the most vital detail ever, thanks. Nice article though, thanks for the heads up, was looking to replace jigloo.