File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Is MiGLayout the best layout manager? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Is MiGLayout the best layout manager?" Watch "Is MiGLayout the best layout manager?" New topic
Author

Is MiGLayout the best layout manager?

Jane Jukowsky
Ranch Hand

Joined: Mar 28, 2009
Posts: 145
I just learned about MiGLayout and am already in love with it. But then, I have not tried JGoodies FormLayout. Should I? Is the latter superior to MiGLayout in any way whatsoever? What other layouts are out there?

Also - the MiGLayout claims to be for manual coders what Matisse layout is for visual editors.. now, I am using a visual editor (Instantiations), and it sort of manages MiGLayout, more or less fine.. generates stupid code of course, but then it respects my corrections of it... should I explore Matisse?

Normally I would not have asked, but I am under a crazy deadline and must keep all exploration to a minimum for the time being. Any suggestions would be greatly appreciated.

Wow, I wish I learned about MiG earlier! What an eye opener. Will never do another BorderLayout or FlowLayout again.
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

I've used both MigLayout and JGoodies FormLayout and I still prefer MigLayout. So stick to MigLayout and be a happy Swing developer


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2090
    
    7
Will never do another BorderLayout or FlowLayout


Too bad, I always like writing code that others is can understand and will be able to maintain. That way when you ask questions you can get help.

The general rule of programming is to use the appropriate tool for the job. You should not force one tool to do everything.
Jane Jukowsky
Ranch Hand

Joined: Mar 28, 2009
Posts: 145

Are you making the point that MigLayout is harder to understand or is less intuitive in FlowLayout or BorderLayout scenaris? How so?
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2090
    
    7
Any layout manager that can pretend to be a BorderLayout or FlowLayout our GridLayout or BoxLayout is obviously more complicated then using the actual layout because you have to configure it in order for it to work like the desired layout you want it to be. Which means you know and understand all the possible constraints that are available. Why do you think GridBagLayout is so confusing?
Jane Jukowsky
Ranch Hand

Joined: Mar 28, 2009
Posts: 145
Err, Rob, you've actually taken a look at MiGLayout before making this statement, have not you? ;-)

By the same logic, one might state that any language that can pretend to be a client-side language and a server-side language and an embedded system language is obviously more complicated than using the languages dedicated for these purposes.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2090
    
    7
you've actually taken a look at MiGLayout before making this statement


Maybe you noticed my comment about all the constraints you need to learn in order to use the layout to get it to work the way you want?

Again I state code written for a specific purpose is easier to understand and use than code written for a general purpose.

This is the whole point of programming you start with something simple and then extend it to add additional functionality. Why do you think Swing has a JTextField, JTextArea and JTextPane? You could get away with simply using a JTextPane, but it is more complicated to use and less efficient than a simple text field that is required in most cases.
Jane Jukowsky
Ranch Hand

Joined: Mar 28, 2009
Posts: 145
Rob Camick wrote:
you've actually taken a look at MiGLayout before making this statement

Maybe you noticed my comment about all the constraints you need to learn in order to use the layout to get it to work the way you want?

Do I take it as a yes?

http://www.miglayout.com/QuickStart.pdf

Here is how you imitate FlowLayout in MiG:


except comp3 does something FlowLayout won't do; but as you can see, it's optional.


Here is how you do the equivalent of Border Layout, only it gives you much, much more control:


That, and much more, you learn by reading 7 pages of Quck Start, and that's 7 pages with a large font. And no, you don't need to know ALL constraints before starting to use one or two, why would you? I still don't know all constraints, and it's already saved me many hours of tedious work.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39535
    
  27
Why do you think GridBagLayout is so confusing?

Doesn't just about everybody think that? I've never heard someone say that GridBag was easy to use; to the contrary, people almost always seemed to try to avoid GridBag because of the messy and unintuitive code it requires.

If you want a GridLayout that allows you to size rows and columns independently, check out GridLayout2. SGLayout does the same, and provides some more options.


Ping & DNS - updated with new look and Ping home screen widget
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2090
    
    7
You still don't understand what I'm saying. I did not say that you can't use MiGLayout to mimic the other layout managers. I maintain this is not always the best approach.

Do you understand the basis for layouts like GridBagLayout, GroupLayout and MiGLayout? One of their design goals was that they can be used by IDE to generate layouts. Now IDE's aren't as smart as humans, they can only use a single layout for the form. As a result you get bloated confusing code that you would never dare try to change manually because you don't know what the effect of making a simple change will do.

As humans (most of us) can think logically and break down a form into logical components and use an appropriate series of nested panels. This results in code that is easier to use understand and maintain.

For example, most applications are designed with a "toolbar", "application panel" and a "status bar". Therefore, the logical layout to use for the top level panel would be a BorderLayout. Yes, MigLayout can mimic a BorderLayout, but you can't tell that from the creation of the layout itself. You need to look at all the "add" statements and the individual constraints of each add before you can determine the "context" of how the layout is being used.

Similiarly for the toolbar, the FlowLayout would be the obvious choice. Again you could use a MigLayout, but you need to look at every single add statment to notice that they don't use any special constraints, therefore you can conclude that the resulting layout will be a flowing layout.

You must remember that more time is spent maintaining code then developing it and it may not be you that maintains it. Therefore by using BorderLayout and FlowLayout you "explicitly" state your intent about how the layout should work. When using MiGLayout you always have to determine the intent by examining the code.

I'm not suggesting don't use MiGLayout. The default layout managers to not handle form type layouts (label, text field pairs) very intuitively, so this is definately a case where mig layout would come in handy.

I just don't agree that MigLayout should be used at all times and in all cases.
Jane Jukowsky
Ranch Hand

Joined: Mar 28, 2009
Posts: 145
Rob, you are making a compelling argument, but if you are arguing against a technology you've never tried in favor of what's been around for a decade, then no offence, but you are just sticking with tried and true and opposing innovation. If you've given a newer technology a try and it did not work for you, then you actually know what you are talking about, your feedback carries weight and is so much more valuable. That's why I asked.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Jane Dodo wrote:Rob, you are making a compelling argument, but if you are arguing against a technology you've never tried in favor of what's been around for a decade, then no offence, but you are just sticking with tried and true and opposing innovation. If you've given a newer technology a try and it did not work for you, then you actually know what you are talking about, your feedback carries weight and is so much more valuable. That's why I asked.


Please listen to what is being said. I've seen nothing in Rob's post to say "don't use MigLayout", but rather, "use the right tool for the job". If it is MigLayout, then use MigLayout, but if it is a simple BorderLayout, then use BorderLayout. What I'm getting out of Rob's posts is to be flexible and to learn the pros and cons of the tools at hand. All I'm seeing in your posts are attempts to twist his words, and I'm not quite sure why.
Jane Jukowsky
Ranch Hand

Joined: Mar 28, 2009
Posts: 145
Not sure where you see twisting the words. I am trying to learn the pros and cons of the tools at hand, that's why I posted this question. Freddy's post was very helpful, it's concrete and comes from someone who's tried both. If Freddy or anyone else made a solid argument as to why FormLayout (or BorderLayout) is better for some jobs, that would have been just as valuable. Ulf's post was very valuable, too, it speaks of some tools that I am not familiar with, and their capabilities. Generalizing, to me, does not answer the question.. that's all. But thank you for sharing your opinion anyway Rob.. you are entitled to it.

Of course some (not all) tools are better for some jobs, who is going to argue with that? That's a truism. I'd like to move on to comparative analysis with other layouts, if no one minds.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is MiGLayout the best layout manager?
 
Similar Threads
Custom painting/graphics
Designing GUIs
Layout Managers and preferred size
Help sorting out what combination of layouts will provide the result I need
miglayout grow problem