Java Swing Layout made extremely easy

on Monday 14 January 2008
If you're a Java developer working on desktop applications that require you to code the interfaces (especially the really complex ones), you'll love what I found.

First, take a look at this page. See that complex looking list? It's made with a custom ListCellRenderer which was created using GroupLayout. Really nice-looking doesn't it? (see the layout tutorial here)

GroupLayout was specifically designed for use with Project Matisse, the GUI builder for the Netbeans IDE, which by the way, is extremely impressive.

Unfortunately, GroupLayout is complex to use and difficult to read if you do not have access to Netbeans and do not wish to use/learn Netbeans solely for the purpose of designing the GUIs. Or maybe you're just old school and prefer to build GUIs by hand (I know, some of the generated code can be icky). What do you do?

You go and download MigLayout of course! Why? Well, go back and look at that fancy list above again and try to estimate how many nested panels you might need should you use the standard layouts, or how many lines of code and the calculations you need for GridBagLayout. Finished? Guess how many lines it takes for MigLayout... seven. Yes, you read it right, just seven simple lines:
cell.setLayout(new MigLayout("nogrid, fillx"));
cell.add(pic,   "dock west");
cell.add(title, "growx");
cell.add(count, "wrap");
cell.add(line1, "growx, wrap");
cell.add(line2, "growx");
cell.add(email);

Impressive, no? Check out the website for guides and Java Web Start demos.

0 responses: