Getting around NetBeans 6 GUI builder’s dependence on Java 6

NetBeans 6 GUI builder is great, but uses a new type of swing layout called the “GroupLayout” by default. This type of layout is only available in Java 6, and so if you try to run your compiled NetBeans 6 code with an older Java version, you get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/swing/GroupLayout$Group
The way to overcome this in NetBeans, is to open up the NetBeans inspector window (lower right when in design mode), right-click on each of your forms and go to properties. Inside the properties window, you will see an option for “Layout generation style”. Change this value from “Standard Java 6 code” to “Swing Layout Extensions Library”.
Recompile, and you will be able to run your app in older Java versions (for example, Java 5).
*Remember to change ALL your forms individually!

Leave a comment