X

Geertjan's Blog

  • June 16, 2009

Registering MigLayout in NetBeans IDE 6.7

Geertjan Wielenga
Product Manager
I started creating a small module that integrates MigLayout into the IDE. That won't help Groovy developers at all, since the GUI Builder generates Java code (and that is unlikely to change). However, it will help Java developers who want to use MigLayout as their LayoutManager.

Already a couple of things are possible—when you create a Swing container in the Matisse GUI Builder, you can set MigLayout as your LayoutManager:

You'll find you have a new node for the layout you chose:

Then you'll also find the MigLayout JAR in the application's Libraries node, which indicates that it has been put on your classpath. In addition, the "initComponents" of a JFrame now has this content:

private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new net.miginfocom.swing.MigLayout());
pack();
}

If you add a JPanel, the "initComponents" ends up like this:

 private void initComponents() {
jPanel1 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new net.miginfocom.swing.MigLayout());
jPanel1.setLayout(new net.miginfocom.swing.MigLayout());
getContentPane().add(jPanel1);
pack();
}

You can tweak the Options window to not have the FQN generated. It's early days yet, so you can't add the MigLayout constraints yet (e.g., "wrap" and so on). Plus, the above are blue blocks, so you can't even add those constraints manually at this point. Also, the typical Matisse GUI Builder features such as align and resize and so on are not supported. All that's currently available is the registration of the MigLayout library and the ability to graphically add it to your project, together with code generation for setting the LayoutManager via the same graphical function.

The source code can be found here on Kenai:

http://kenai.com/projects/nbmiglayout/

If you have ideas about how the user should be able to graphically set MigLayout constraints, probably via drag-and-drop, I guess, feel free to join the project and share your ideas.

Join the discussion

Comments ( 5 )
  • collinm Friday, May 27, 2011
    with netbeans 7 and the source code (don't know if a plugin is directly available), i get:
    Cannot load component class net.miginfocom.swing.MigLayout from IDE library: MigLayout.
    The class must be compiled and must be on the classpath of the project to which fhis form belongs.
  • guest Sunday, October 30, 2011

    You don't actually tell us how to add this layout manager.


  • guest Friday, September 21, 2012

    Please expand/update this article :)


  • guest Wednesday, January 2, 2013

    How to add MigLayout component in NetBeans7.2 IDE??


  • Michael Cress Friday, February 5, 2016

    Steps to use module:

    1.) Check out SVN repository from http://kenai.com/projects/nbmiglayout/

    2.) Add the Utilities API to the list of module dependencies:

    - Open module project within Netbeans.

    - Right click on project -> properties -> Categories: Libraries -> Module Dependencies -> Add Utilities API

    3.) In Installer.java, change "LayoutSupportRegistry.registerSupportForLayout(MigLayout.class, MigLayoutSupport.class);" to "LayoutSupportRegistry.registerSupportForLayout(MigLayout.class.getName(), MigLayoutSupport.class.getName());"

    4.) Clean and build project.

    5.) Right click, select Create NBM

    6.) In IDE menubar, select Tools->Plugins->Downloaded->Add Plugins

    - Browse to module directory. Select build directory. Find .nbm file and select it. Click Open.

    7.) Continue the registration process.


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.