Wednesday, June 8, 2011

Hierarchy View in Project Panel of NetBeans IDE

This post will cover following topics, questions:

  • How to change the package display type in NetBeans IDE?
  • How to see packages as hierarchical tree in the Projects Panel of NetBeans IDE?
  • Where is the menu to change List view to Tree view for packages in NetBeans IDE?
  • Customizing the display of Projects Panel in NetBeans IDE.
The preferences for how to see the package hierarchy in Projects Panel change from developer to developer.  Some times I like the flat display of the default NetBeans IDE Projects Panel which shows all the packages one below the other and all the classes in the package as a list below the package fully qualified name.  This makes the Projects panel only 4 node deep.

NetBeans IDE also allows us to change the display mode from List to Tree for the packages.  So instead of flat fully qualified name mode we can change the display to Tree like hierarchy mode where all the folders will also be converted to nodes and the depth of the Projects Panel tree will be deeper.

To do this we have to right click on an empty area of the Projects Panel.  The "View Java Packages As" menu only appears when we right click on an empty space of the Projects Panel.  This menu has two options and the List one is selected by default.  We can choose the Tree option to change the display of the Projects Panel to hierarchy mode.

When we change the mode to hierarchy the display looks more or less like the Files panel and the packages are shown as folder nodes.  This also makes the tree deeper according to how deep the packages are in hierarchy.

It is good to know the way to switch between these modes so that we can change the mode for some time if we want and again change it back to what it was.

The NetBeans IDE remembers your last choice by saving the preference in user directory, so when the NetBeans IDE is opened again next time the Tree mode or List mode of the Projects Panel is maintained.  

with regards
Tushar Joshi, Nagpur

Sunday, June 5, 2011

Downloading OpenJDK7 Binary for Mac OS X

 NetBeans IDE 7.0 has support for the bleeding edge OpenJDK 7.0 build release.  Even if Mac OS X does not have an official binary distribution on the Open JDK site yet, we can still get a DMG bundle of the latest build of Open JDK7 to test on Mac OS X.

Let us go through steps we need to perform to install and test OpenJDK7 on Mac OS X.  The OpenJDK7 latest binary is available on the Google Code site

The latest build available there today is seen as b144 which is the latest build available on the OpenJDK7 download page also.  This bundle is available in 32 as well as 64 bit version.

They have created a nice DMG bundle which shows the Java mascot when we open the DMG.

The installation starts as a usual Mac OS X installer bundle.  As seen from the below image this version takes 179.6 MB on disk.

Once we have installed the OpenJDK7 latest binary build.  We can start the Java Preferences application from the Spotlight and can see two more JDK instances available in the list of JDK available.  One for 32 bit and one for 64 bit.

If we choose we can set the JDK7 version default here.  I choose not to set it as default yet as it is not an official version from OpenJDK7 site.  We can still use this JDK from NetBeans by registering it as a JDK platform.

For registering the JDK7 as platform on NetBeans IDE 7.0 open up the Java Platform Manager from Tools > Java Platforms menu.  The new JDK7 will not be seen yet.  We will have to press the Add Platform button.

NetBeans IDE will point you to correct Java Library directory from where you can choose the openjdk-1.7 instance of the java platform.

When we select the openjdk-1.7 folder NetBeans IDE correctly fills all the required information and presents a prefilled dialog boz for Add Java Platform and we just have to click Next.

JDK 1.7 will start appearing in the available Java Platforms list.  As we can see NetBeans detects all the required files and documents required for registering the JDK 1.7 platform.

Now we can start any Java project and set the Java Platform as JDK 1.7.  For that we will have to open the Project Customizer by right clicking the project and choosing the Properties menu.

We need to change the Java Platform entry in the Libraries node first.

Once the Java Platform is set as JDK 1.7 in the Libraries Node it becomes available in the Sources Node also in the Source/Binary Format combo box.  We will have to set this as JDK 7 also.

Now this project is set to be compiled and run under Java 7 platform.  We can test this by adding some generics statement and NetBeans IDE offers a hint to use diamond operator (Project Coin)

NetBeans IDE will also apply those changes to the code when we select the hint as seen in the image below.

So this is how we can install latest JDK 1.7 on our Mac machines and test the JDK 7 version from NetBeans IDE 7.0 which supports JDK 1.7 features now.

with regards
Tushar Joshi, Nagpur