Take the 2-minute tour ×

What java GUI layout manager does everyone use? Lately, I have been using MigLayout, which has some powerful component controls. Just wanted to see what other developers are using other than the standard JDK ones.

share|improve this question

22 Answers 22

up vote 17 down vote accepted

MiGLayout is the GUI layout manager which is widely used by Java Developers.

share|improve this answer
This answer is a bit quick. We would expect justifications, pros and cons... –  jfpoilpret Feb 4 '09 at 8:17
What makes MiGLayout so good? –  Jay R. Feb 26 '10 at 23:04
i just tried it and it is AWESOME! Just have a look at the website and you will know for sure. No need to justify in words when you can see it in action!! –  Roopesh Shenoy Apr 3 '11 at 15:58
Let's add some pros and cons. The most outstanding feature of MigLayout is probably its debug mode, showing the boundaries of cells and components with dotted lines overlaid on the UI. This is vital to understand why a layout goes bad. The cons... well, it's not part of the JDK, but it's just a 75k dependency. –  Emmanuel Bourg Oct 25 '11 at 7:59
MigLayout is easy to learn and do excatly what you expect. Just print its "Cheat sheet". It has nice sample application. It is possible to write readable and changeable layouts. It has useful debug mode. I wrote Swing applications for 2 years. Trust me do not use standard layouts it is paintful way to hell, use MigLayout. –  bugs_ Mar 26 '12 at 13:39

GridBagLayout is usable. Once you get used to using it, it works great. I think the standard JDK layout managers are pretty powerful on their own. Plus, you get to minimize dependency on 3rd party libraries.

share|improve this answer

MiG and FormLayout (JGoodies) are both excellent for manual layout (And almost all layout eventually becomes manual). My biggest piece of advice is to design your views so that you can completely rip out the layout and re-implement it without impacting your application (good separation of view and controller is key here).

Definitely take a look at JGoodie's PresentationModel approach for implementing 'dumb' views. I use this technique with a GUI builder (I use GroupLayout with the Jigloo GUI builder plugin) for tossing off quick prototypes. After 3 or 4 iterations, that usually goes out the window and we do a re-implement using MiG or FormLayout.

EDIT: Since I wrote this, I have moved to using MiG for all of my layouts, and I no longer use a GUI builder - it's just way too easy to lay things out using MiG.

share|improve this answer

The last Swing application I worked on used JGoodies' FormsLayout.

share|improve this answer

I use the GridBagLayout. It seems to take alot of code, but it makes very good looking layouts.

I also like to combine BorderLayout with GridBagLayout panels for great customizability.

share|improve this answer

I use to go for GridBagLayout for the control, but since java1.6 I'm going to use GroupLayout Is awsome.

Here an screenshot and sample code to use it!.

alt text

    private void layoutComponents(){
        JPanel panel = new JPanel();

        GroupLayout layout = new GroupLayout(panel);


        SequentialGroup hGroup = layout.createSequentialGroup();

        JLabel nameLbl  = new JLabel("Name");
        JLabel countLbl = new JLabel("Amount");
        JLabel dateLbl  = new JLabel("Date(dd/MM/yy)");



        SequentialGroup vGroup = layout.createSequentialGroup();


        frame.add( panel , BorderLayout.NORTH );
        frame.add( new JScrollPane( textArea ) );
share|improve this answer
the source code in the link at the end was deleted :-( –  user1097772 Feb 9 '12 at 11:17
I've removed the dead link . . –  OscarRyz Feb 9 '12 at 19:23

I use DesignGridLayout for most of my panels.

For the rare panels that DesignGridLayout cannot fully handle, I use a mix of Borderlayout and DesignGridLayout.

With DesigngridLayout you can manually code your layouts with a minimum number of lines of code, that are easy to type and read:

DesignGridLayouut layout = new DesignGridLayout(myPanel);
layout.row().center().add(btnOK, btnCancel);

Each row of the panel grid is defined by one line of code. As you can see, "drawing" your panel is quite straightforward.

In addition, I find DesignGridLayout has some unique features (such as its "smart vertical resize").

share|improve this answer
Oops, I forgot the usual disclaimer: "I am one of DesignGridLayout project owners";-) –  jfpoilpret Jan 6 '09 at 5:49

I'm a big fan of using TableLayout instead of GridBagLayout. Everything just makes sense, whereas every time I try to use GridBagLayout it crushes my soul.

share|improve this answer

GridBagLayout is powerful but quite primitively: the code that wires up the layout is very verbose. This utility library (actual just 1 jar file containing about 10 classes) simplifies a lot of works: http://code.google.com/p/painless-gridbag/ The following snippet is quoted from the home page of that site:

    PainlessGridBag gbl = new PainlessGridBag(getContentPane(), false);


share|improve this answer
This has the advantage you can just copy the 10 classes into your project and not be dependent on a third-party library... –  Epaga Jan 19 '10 at 9:58

As a general overview, you might find an article I wrote a loooong time ago at sun to be useful. It's not up to date with the latest layout managers, but it concentrates on effective nesting of layout managers, rather than trying to do everything with one layout.

See http://developer.java.sun.com/developer/onlineTraining/GUI/AWTLayoutMgr

share|improve this answer

I've found that for any non-trivial GUI I use multiple layouts with nested sub-panels where the main panel may have a GridBagLayout and each sub-panel (typically without a border or indication that it is a panel) uses a simpler layout where possible. Typically I'll use BorderLayout, FlowLayout, and BoxLayout for smaller, simpler sub-panels. By dividing small sections of the GUI into sub-panels and using the simplest layout possible to control that section of the GUI you can create complex, well arranged displays without too much headache from GridBagLayout's many options. Also, by grouping like display functionality into a panel, it creates more readable code.

share|improve this answer

Spring layout which was developed for the mantissa gui builder which is part of netbeans.

share|improve this answer
I thought Matisse used GroupLayout. –  Michael Myers Sep 22 '08 at 20:03
There was a SpringLayout GUI builder in the BDK. I wouldn't recommend it. Internally, the GroupLayout implementation does use what it calls springs. –  Tom Hawtin - tackline Sep 22 '08 at 20:21

I've used GroupLayout as well. Again, its a standard JDK layout manager as of Java6, but you can find the library separate as well.

share|improve this answer

I've always been a big fan of the GridBagLayout. It resembles HTML tables a lot so it is intuitive to those web programmers.

share|improve this answer

I started off using various nested layouts, then moved over to GridBagLayout (which is pretty frustrating). Since then I tried FormLayout (but found it wasn't suited to anything but forms) and settled firmly on TableLayout, which overall I'm very happy with.

Since then I've discovered MiGLayout and although I haven't done much more than play with it, it seems very capable, quite similar to TableLayout and probably a little cleaner.

The big plus for me is that MiGLayout is set to become part of the JDK, so I intend to use it pretty much exclusively when it does.

The other thing to remember is that no matter which heavy-weight LayoutManager you settle on, there is always a place for some of the simpler layout managers such as GridLayout. I've seen some horrible things done with GridBagLayout that could have been done much more easily with a simpler layout manager.

share|improve this answer

I prefer to minimize dependencies on 3rd party libs, so it's usually BoxLayout for dialogs and GridBagLayout for "complicated" layouts. GridBagLayout is easy enough to understand, but a bit hard to configure. I wrote myself a tool for creating the code from HTML layouts (hope that helps others too): http://www.onyxbits.de/content/blog/patrick/java-gui-building-gridbaglayout-manager-made-easy

share|improve this answer

The only layout manager that I have found, that I actually like is the Relative Layout Manager. The Relative Layout Manager works in a way that is consistent with how dialog boxes are conceptually organized. One draw-back is that while this layout manager deals with additive constraints. It does not seem to deal with ratio constraints. Fortunately it is pretty well designed, and I was able to implement this feature.

share|improve this answer

I use BorderLayout 90% of the time while nesting BoxLayout and SpringLayout

share|improve this answer

I'm a bit of Java newbie.

I tried GridBagLayout, gave up, then tried BoxLayout, then gave up, then made my own Custom Layout which worked. With GridBag and Box I put my best guess in and the Layout engines decided to do something different, without any apparent way to debug them.

With my custom layout, I could print out coordinates and widths and heights, to find out where it was going wrong. Its a bit mathy placing things but you've got the full power of java to use rather than the limited vocabulary of one of the builtin layout managers.

Of course it was just for a home project, you'd never be allowed to do this at work.

share|improve this answer

I use GridBagLayout for form like layouts, use BorderLayout for simple layouts, and FlowLayout for number of horizontal icons/buttons that have some spaces in between. Netbeans is also a good GUI builder that can avoid a lot of tedious layout codings to save your time.

share|improve this answer

I have started using Swing recently and I am using GridBagLayout.

share|improve this answer

I was sick of all those layoutmanagers that needed alot of setup, werent very readable or exhausting to do manually, so I wrote my own very simple laoutmanager which uses the abstraction of two photocorners keeping each component in place. You can add your component like this: parent.add(child,"topleft(0, 0.5)bottomright(0.5,1.0)");

Have a look here https://github.com/hageldave/UsefulStuff/blob/master/src/PhotoCornersLayout.java ;) you're responisble for a correct layout yourself though, cause it's not checking overlappings or other shortcommings of your layout.

share|improve this answer

Your Answer


