 |
Home | Changes | Index | Search | Go
Mig Layout is an extremely flexible layout manager. It can handle just about any layout thrown at it and this with great ease.
http://www.migcalendar.com/miglayout/swingdemoapp.jnlp
There is a Quick Start Guide, White Paper, Cheat Sheet and a lot of other resources at the Mig Layout site.
Here is the Webstart Demo of Mig Layout that shows how Mig Layout works. Check out the last panels in the list, it is the implementation of the panel for the showdown. .
This is the code for the panel posted by John Conner in the Layout Manager Showdown. As you can see it is easy to understand and requires no extra code other than the simple string constraints.
It follows every single rule set up bu John, it does not cheat in any way. The panel will follow the preferred gaps and indents on the platform it is run on. The spacing will for instance be correct, and thus slighty larger, on Mac OS X.
I have at the bottom also posted the code for a slightly fixed up version of the panel. Must constraints has been simplified since making better layouts is actually easier with Mig layout since that is usually the default behavior.
Can it align components across other components? For example, can it both left and right align the 'phone' text field with the 'city' text field on the other side of the two address fields?
Yes. There are many ways components can be aligned.
Does your manager know about platform specific gaps and spacing among components. Just curious.
Yes. And it is easy to change them or add new ones.
Can the text fields, labels, etc grow and shrink when the text is localized?
Yes.
Just how much code do I have to write? Java code? Declarative XML?
There are only the constraints used when creating the layout manager instance, which is mostly an optional grid size specification, and the layout constraints for each component. So there are no extra needed builders, arrays of components, grid statements or such. It's super simple.
Can I nest panels?
Yes, but the layout manager is so powerful that you won't need that for layout purposes. For component reuse it might be good to nest panels though.
Can it align components along a baseline. For example, the new GroupLayout can align labels and text fields along the text baseline...that's nice.
Yes, on JDK 6.0.
What's the licensing?
Source code is released under BSD and the everything is 100% free and downloadable from our site.
Will this work for bi-directional locales? How difficult would it be to mirror the layout for a right-to-left locale?
Yes. One can use “leading” instead of “left” for instance. Mig Layout supports both right-to-left and bottom-to-top layouts and recognizes this automatically depending on Locale (but it can also be set explicitly).
What else should we evaluate?
It handles different units (millimeter, screen percentage, logical pixels, an many many more).
There is support for almost every thing any other layout manager has and if not it will probably be added soon.
This is the only code that is needed to create the layout:
JPanel p = new JPanel(new MigLayout("", "[]15[][grow,fill]15[grow]"));
JScrollPane listScrollPane = new JScrollPane(new JList(new String[] {"Mouse, Mickey"}));
p.add(listScrollPane, "spany, growy, wmin 150");
p.add(new JLabel("Last Name"));
p.add(new JTextField());
p.add(new JLabel("First Name"), "split"); // split divides the cell
p.add(new JTextField(), "growx, wrap");
p.add(new JLabel("Phone"));
p.add(new JTextField());
p.add(new JLabel("Email"), "split");
p.add(new JTextField(), "growx, wrap");
p.add(new JLabel("Address 1"));
p.add(new JTextField(), "span"); // span merges cells
p.add(new JLabel("Address 2"));
p.add(new JTextField(), "span");
p.add(new JLabel("City"));
p.add(new JTextField(), "wrap"); // wrap continues on next line
p.add(new JLabel("State"));
p.add(new JTextField());
p.add(new JLabel("Postal Code"), "split");
p.add(new JTextField(), "growx, wrap");
p.add(new JLabel("Country"));
p.add(new JTextField(), "wrap 15");
p.add(new JButton("New"), "span, split, align left");
p.add(new JButton("Delete"));
p.add(new JButton("Edit"));
p.add(new JButton("Save"));
p.add(new JButton("Cancel"), "wrap push");
|