Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

MigLayout: Easing the Pain of Swing/SWT Layout Management : Page 3

Get a high-level overview of the MigLayout Swing/SWT layout manager, along with an example that demonstrates its conciseness and power.


advertisement
Important, High-Use MigLayout Keywords
Although MigLayout comes with a wide variety of keywords, there are certain ones that you will find yourself using most often, namely:
  • wrap: Used on a control (e.g., add(new JButton("OK"),"wrap")), it tells the layout to wrap to the next line.
  • wrap x: Used as a global layout constraint (e.g., new MigLayout("wrap 3")), it tells the layout to automatically wrap to the next line every x controls that are added.
  • span: Used on a control, it tells the control to occupy the remainder of the row.
  • span x | span x y: Used on a control, it tells the layout that this control will occupy a cell that spans x columns (or x columns and y rows)
  • split | split x: Used on a first control in a cell, it tells the layout manager to split the cell so that multiple controls can be added into it. The next x controls that will be added will automatically be in the same cell (or if the split is used without a value, it will wait until the next wrap keyword is encountered).
  • grow: Used at a layout, column, row, or control level, it tells basically the layout to occupy the full available space. For example, if you wanted to define a layout with three columns where the middle one grows as the window expands, you would define it as new MigLayout("","[] [grow] []").
  • top, left, bottom, right: These are basic vertical and horizontal alignment indicators that can be used at any level (layout, column, row, or control).
  • flowy: It changes the flow from horizontal to vertical.
  • sg x: Used on a control, sg stands for size group. It allows you to indicate that multiple controls should have the same size. This is very useful when you want all command buttons to be of the same width. Here's an example:

    add(new JButton("OK"),"sg 1"); add(new JButton("Cancel"),"sg 1"); add(new JButton("Apply"),"sg 1");

Those are the base keywords you need to learn in order to become productive quickly.



Layout Management Can Be Easy
The next time you struggle with manually coding layouts or trying to maintain a complex screen in a UI designer, you owe it to yourself to investigate MigLayout. This powerful and easy layout manager is a fine example of how most of the Java platform's strength today lies not in its base libraries but in its extremely rich open-source ecosystem.



Jacek Furmankiewicz is a Senior Java EE and Erlang/OTP developer at Radialpoint. He has 15 years of professional IT experience and is a Sun Certified Java Programmer (SCJP).
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap