Forum Controls
Spotlight Features

The Rich Engineering Heritage Behind Dependency Injection

Andrew McVeigh takes us on a tour of the rich heritage behind dependency injection, what it represents, and tells us why its here to stay.

NetBeans 6: Matisse Updates

NetBeans 6 delivers great updates to the Matisse GUI builder. Spend a few minutes with Roman Strobl and get an expert briefing on what's new and what has changed.

Introduction to Groovy Part 3

In this, the third and final installation of Andres' Introduction to Groovy series, you learn about how Groovy handles variable numbers of arguments, named parameters, currying, and more about Groovy operators. Including, some new operators.

Easier Custom Components with Swing Fuse

Swing Fuse (actually just Fuse), is a framework designed to make it easier to create your own custom desktop components. In this article, Daniel Spiewak shows you how to get started and provides sample source code you can download.

Benchmark Analysis: Guice vs Spring

Willam Louth shows how he uses JXInsight Probes to investigate probable performance issues with code bases that he is not familiar with. He also highlights possible pitfalls in creating a benchmark, as well as in the analysis of results.
Replies: 21 - Pages: 2   [ 1 2 | Next ]
Threads: [ Previous | Next ]
  Click to reply to this thread Reply

GUI Layouts for Swing and SWT: Part 3

At 4:10 PM on Nov 19, 2007, Mikael Grev DeveloperZone Top 100 wrote:

 

 

 

  MigLayout is a Layout Manager for Swing and SWT created to replace all current layout managers and introduces a very easy to understand yet powerful syntax that resembles CSS.

  This is the third posting in a series that will introduce MigLayout and show how easy it is to use. If you have not read part 1 and part 2 , do so first.

  If you want to start using MigLayout, just head over to miglayout.com and everything will be there waiting for you, including more examples. Miglayout is 100% free and Open Source (BSD) .

 

Component Sizes, and not Just Pixels

The default component sizes in Swing and SWT is provided by the framework, either by the widget directly (SWT) or by the L&F Delegate (Swing). You can also set them explicitly by setting the size in pixels on the widget.

  Unfortunately this mean that you need to provide both the width and height. You cannot, neither in Swing or SWT, use the widget's default height (which is depending on the Font) and set a specific width without sub classing the widget. Fortunately with MiG Layout you can. You can set a new width without changing the widget supplied height. You can even set the size in any of the supported units, such as millimeters, inches or percentage of the parent.

  Swing supports the notion of minimum, preferred and maximum size. SWT does not; it only has the notion of a preferred size. MigLayout allows you to override all these sizes and adds support for minimum, preferred and maximum size to SWT.

  The default unit used when not specified is changeable using the PlatformDefaults class. By default it is "Logical Pixels" which means a one to one mapping to normal pixels on normal DPI screens. On HiDPI screens it will scale to be the same size, as when measured using a ruler, ensuring automatic resolution independence.

  MigLayout use a simple colon separated notion when specifying sizes. There are a few short cuts to make it simple to for instance set all of the sizes to the same value.

  Examples:

// parent.add(widget, "...");
 
"width 10"             // The preferred size is 10. Min/Max is left untouched.
"width 10:20:30"       // The min, preferred and max size respectively.
"width 10!"            // Min, preferred and max size set to 10.
"height 10mm"          // Preferred size is 10 millimeter.
"w 10"                 // "w" can be used instead of "width". "h" instead of "height" 
"height 10:20"         // If only two sizes are specified that is min and preferred.
"height 10::20"        // Min and max set. Preferred untouched.
"height (10mm + 10px)" // Math expressions can be used everywhere in MigLayout..
"width pref+10px"      // "pref" is the preferred size as reported by the widget/delegate.


Cheers,
Mikael Grev

1 . At 6:48 PM on Nov 19, 2007, Kirill Grouchnikov wrote:
  Click to reply to this thread Reply

Re: GUI Layouts for Swing and SWT: Part 3

MiG Calendar --> MiG Layout (?)
2 . At 1:13 AM on Nov 20, 2007, Mikael Grev DeveloperZone Top 100 wrote:
  Click to reply to this thread Reply

Re: GUI Layouts for Swing and SWT: Part 3

Oops. Slipped.. Thanks!
Mikael Grev (grev at miginfocom dot com)
MiG Java Calendar Component, MiG Layout for Swing/SWT (Vote -> JDK)
3 . At 5:11 AM on Nov 21, 2007, DJDaveMark wrote:
  Click to reply to this thread Reply

Re: GUI Layouts for Swing and SWT: Part 3

_
Interesting LayoutManager but I still say ZoneLayout is the most flexible/powerful e.g...

Part 1
====
ZoneLayout layout = ZoneLayoutFactory.newZoneLayout();
JPanel panel = new JPanel(layout);
layout.addRow("a<a1b~-b3c<c1d~-d");
layout.addRow("................6");
layout.addRow("e<e1f....~-.....f");
 
panel.add(new JLabel("First Name"), "a");
panel.add(new JTextField(15), "b");
panel.add(new JLabel("Surname"), "c");
panel.add(new JTextField(15), "d");
panel.add(new JLabel("Address"), "e");
panel.add(new JTextField(), "f");
panel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
Part 2
====
ZoneLayout layout = ZoneLayoutFactory.newZoneLayout();
JPanel panel = new JPanel(layout);
layout.addRow("wm~-m");
layout.addRow(".n~-n");
layout.addRow(".c..e");
layout.addRow("|.*.|");
layout.addRow("!.+.!");
layout.addRow("...ce");
layout.addRow("ws~-s");
 
panel.add(createLabel("West Panel"), "w");
panel.add(createLabel("North 1 Panel"), "m");
panel.add(createLabel("North 2 Panel"), "n");
panel.add(createLabel("South Panel"), "s");
panel.add(createLabel("East Panel"), "e");
panel.add(createLabel("Center Panel"), "c");
panel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
Part 3
====
Even with the most complicated layouts you typically don't need to mess with the sizes, it just works, WYSIWYG...
ZoneLayout layout = ZoneLayoutFactory.newZoneLayout();
layout.addRow("a.-~.a");
layout.addRow("b.+*.b");
layout.addRow(".....6");
layout.addRow("...c2d");
 
ZoneLayout aLayout = ZoneLayoutFactory.newZoneLayout();
aLayout.addRow("a>a2b-~b3c>c2d-~d", "valueRow");
aLayout.addRow("6................", "valueRow");
aLayout.addRow("e>e2f......-~...f");
 
ZoneLayout bLayout = ZoneLayoutFactory.newZoneLayout();
bLayout.addRow("a>a2b-~b2c-c");
bLayout.addRow("...........6");
bLayout.addRow("g........d-d");
bLayout.addRow("...........6");
bLayout.addRow("...+*....e-e");
bLayout.addRow("...........6");
bLayout.addRow(".........f-f");
bLayout.addRow(".......g...!");
 
JPanel namePanel = new JPanel(aLayout);
aLayout.insertTemplate("valueRow");
namePanel.add(new JLabel("First Name:"), "a");
namePanel.add(new JTextField(15), "b");
namePanel.add(new JLabel("Last Name:"), "c");
namePanel.add(new JTextField(15), "d");
System.out.println(new JTextField(15).getMinimumSize());
aLayout.insertTemplate("valueRow");
namePanel.add(new JLabel("Title:"), "a");
namePanel.add(new JTextField(15), "b");
namePanel.add(new JLabel("Nickname:"), "c");
namePanel.add(new JTextField(15), "d");
namePanel.add(new JLabel("Display Format:"), "e");
namePanel.add(new JComboBox(new String[]{"1", "2"}), "f");
namePanel.setBorder(BorderFactory.createCompoundBorder(
        BorderFactory.createTitledBorder("Name"),
        BorderFactory.createEmptyBorder(5, 5, 5, 5)
));
 
JPanel emailPanel = new JPanel(bLayout);
emailPanel.add(new JLabel("Email Address:"), "a");
emailPanel.add(new JTextField(15), "b");
emailPanel.add(new JButton("Add"), "c");
emailPanel.add(new JButton("Edit"), "d");
emailPanel.add(new JButton("Remove"), "e");
emailPanel.add(new JButton("Advanced"), "f");
emailPanel.add(new JList(), "g");
 
emailPanel.setBorder(BorderFactory.createCompoundBorder(
        BorderFactory.createTitledBorder("E-mail"),
        BorderFactory.createEmptyBorder(5, 5, 5, 5)
));
 
JPanel panel = new JPanel(layout);
panel.add(namePanel, "a");
panel.add(emailPanel, "b");
panel.add(new JButton("OK"), "c");
panel.add(new JButton("Cancel"), "d");
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
 
JFrame frame = new JFrame();
frame.add(panel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
4 . At 11:11 AM on Nov 21, 2007, Mikael Grev DeveloperZone Top 100 wrote:
  Click to reply to this thread Reply

Re: GUI Layouts for Swing and SWT: Part 3

Given that you posted on my topic "GUI Layouts for Swing and SWT" I guess this ZL works for SWT as well?
Mikael Grev (grev at miginfocom dot com)
MiG Java Calendar Component, MiG Layout for Swing/SWT (Vote -> JDK)
5 . At 3:51 AM on Nov 23, 2007, DJDaveMark wrote:
  Click to reply to this thread Reply

Re: GUI Layouts for Swing and SWT: Part 3

Yip indeed,

It even even works with SwingX. Although there is one small gotcha. If you use a JXTitledPanel then set it's layout manager to a ZoneLayout you'll get a java.lang.RuntimeException "Component xyz is not bound to a zone in this layout", due to the fact that the JXTitledPanel adds other components to the layout make a titled header. It isn't a bug. It's just that the two obviously don't know how to interact. Here's how to produce the error...
ZoneLayout layout = ZoneLayoutFactory.newZoneLayout();
layout.addRow("c*+c");
 
JXTitledPanel jxPanel = new JXTitledPanel("JXTest");
jxPanel.setLayout(layout);
 
JButton center = new JButton("center");
jxPanel.add(center, "c");
 
JFrame frame = new JFrame();
frame.setContentPane(jxPanel);
frame.pack();
frame.setVisible(true);

and here's a work around...
ZoneLayout layout = ZoneLayoutFactory.newZoneLayout();
layout.addRow("c*+c");
 
JPanel zonePanel = new JPanel(layout);  //Edit
 
JButton center = new JButton("center");
zonePanel.add(center, "c");             //Edit
 
JXTitledPanel jxPanel = new JXTitledPanel("JXTest");
jxPanel.add(zonePanel);                 //Edit
 
JFrame frame = new JFrame();
frame.setContentPane(jxPanel);
frame.pack();
frame.setVisible(true);
6 . At 4:21 AM on Nov 23, 2007, Mikael Grev DeveloperZone Top 100 wrote:
  Click to reply to this thread Reply

Re: GUI Layouts for Swing and SWT: Part 3

Strange, your docs says that it doesn't work for SWT...
Mikael Grev (grev at miginfocom dot com)
MiG Java Calendar Component, MiG Layout for Swing/SWT (Vote -> JDK)
7 . At 5:43 AM on Nov 23, 2007, Walter Laan wrote:
  Click to reply to this thread Reply

Re: GUI Layouts for Swing and SWT: Part 3

Layout by ASCII art ;)

Currently I'm using a custom sub class from Clearthought's TableLayout. AbstractDialog is based on Jide's StandardDialog. Your last example:
class SomeDialog extends AbstractDialog {
public SomeDialog(Window owner) {
   super(owner, OK_CANCEL); // why layout buttons again for every dialog?
}
 
public Component createContentPanel() {
  JPanel panel = new JPanel(new BorderLayout());
  // if user panel wasn't a fixed form, I would use a split pane here
  panel.add(createUserPanel(), BorderLayout.PAGE_START);
  panel.add(createEmailPanel(), BorderLayout.CENTER);
  return panel;
}
 
public Component createUserPanel() {
  JPanel panel = new JPanel();
  CustomTableLayout layout = new CustomTableLayout(panel, new double[][] {
    { PREFERRED, FILL, PREFERRED, FILL }, // columns
    { PREFERRED } // extra rows get auto added if needed
  });
 
  // adds label/value pair
  layout.addNext("First name", new JTextField(15));
  layout.addNext("Last name", new JTextField(15));
  layout.addNext("Title", new JTextField(15));
  layout.addNext("Nickname", new JTextField(15));
  layout.addNext("Display format");
  layout.addNext(new JComboBox(..), 3, 1, ""); // span 3 columns, one row, no extra constraints
  return panel;
}
 
public Component createUserPanel() {
  JPanel panel = new JPanel(new BorderLayout());
  // like the dialog buttons, a row of button is something you want to re-use
  List<Action> actions = Arrays.asList(addAction, editAction, deleteAction, advancedAction);
  panel.add(ActionFactory.createToolbar(actions), BorderLayout.PAGE_START);
  panel.add(new JScrollPane(new JList()), BorderLayout.CENTER);
  panel.setBorder(BorderFactory.createTitleBorder("Email"));
  // and we can use the actions to make a popup menu as well ;)
  ActionFactory.createPopupMenu(panel, actions);
 
  return panel;
}
}

Since MigLayout is more flexible (with no defining before hand), it might make a good replacement for the table layout. The dock options make it more flexible replacement for BorderLayout, but I'm not sure I need that more flexible.
public Component createUserPanel() {
  JPanel panel = new JPanel();
  CustomMigLayout layout = new CustomMigLayout(panel);
 
  // adds label/value pair
  layout.addNext("First name", new JTextField(15));
  layout.addNext("Last name", new JTextField(15), "wrap");
  layout.addNext("Title", new JTextField(15));
  layout.addNext("Nickname", new JTextField(15), "wrap");
  layout.addNext("Display format", new JComboBox(..), "growx");
  return panel;
}

where addNext would something like this:
public void addNext(String name, Component value, String... constraints) {
  JLabel label = new JLabel(name + ":"); // or can leave colon out
  lanel.setLabelFor(c);
  panel.add(label, "label");
  List<String> cs = new ArrayList<String>();
  cs.add("growx");
  cs.addAll(Arrays.asList(constraints));
  panel.add(c, StringUtils.join(cs, ','));
}

Note that I haven't tested any of this code or wrote an actual CustomMigLayout, but my point is when writing a layout by hand, I want to re-use code where possible and keep it as simple as possible.
Flexible and powerful is nice if you need it. But isn't it then getting to complex for the user (and I don't have code completion for string constraints ;)).
My motto: if you can't solve it with a split pane, border layout and a form layout, it's too complex.
If you need that complexity, switch to a docking framework where the user can configure it himself if he wants to.
8 . At 3:44 PM on Nov 25, 2007, Jonathan wrote:
  Click to reply to this thread Reply

Re: GUI Layouts for Swing and SWT: Part 3

Hi DJ. A while back I thought I had a great idea for a layout manager - the idea was extremely similar to ZoneLayout. While I think it's really cool that such a layout manager now exists, I don't think I will ever use it.

Maybe I'm not giving it a fair chance, but I don't think I should have to read the manual in order to understand the general intent of the code. All the special characters: < , ~ , - , . mean absolutely nothing to me whereas span , grow , and fill already give me an idea of what the layout manager is trying to accomplish.

Since you're intimately familiar with ZoneLayout, I'm sure the ZoneLayout code below makes more sense to you than the MigLayout code following it. I think it's important to look at both layout managers as if you were completely new to them.

As someone new to ZoneLayout... if I wanted to learn it without digging into the documentation I might try modifying someone else's existing code. Looking at your example below, I would have no idea what I could change without "breaking" the layout. For example, can I replace a<a with a.. or replace a < with a . ? Since I have no idea what the intent of those special characters are, I'm not sure if I can change them.

ZoneLayout
ZoneLayout layout = ZoneLayoutFactory.newZoneLayout();
JPanel panel = new JPanel(layout);
layout.addRow("a<a1b~-b3c<c1d~-d");
layout.addRow("................6");
layout.addRow("e<e1f....~-.....f");
 
panel.add(new JLabel("First Name"), "a");
panel.add(new JTextField(15), "b");
panel.add(new JLabel("Surname"), "c");
panel.add(new JTextField(15), "d");
panel.add(new JLabel("Address"), "e");
panel.add(new JTextField(), "f");
panel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));


With the miglayout code below, I might try removing grow, or adding grow,fill in between one of the empty brackets [] . What I will probably find is that, "hey, these represents column constraints and I just set the first column to grow and fill!" Without digging into the manual at all I already feel comfortable with this code.

MigLayout
setLayout(new MigLayout("", "[][grow,fill][][grow,fill]"));
add(new JLabel("First Name"));
add(new JTextField(15));
add(new JLabel("Surname"));
add(new JTextField(15), "wrap");
add(new JLabel("Address"));
add(new JTextField(), "spanx");
9 . At 12:34 PM on Nov 27, 2007, DJDaveMark wrote:
  Click to reply to this thread Reply

Re: GUI Layouts for Swing and SWT: Part 3

Hi Jonathan,

You don't have to read the ZoneLayout manual. There is a one page guide which explains everything I'm going to use here. Starting off with the simplest code I'm gonna change things bit by bit...
ZoneLayout layout = ZoneLayoutFactory.newZoneLayout();
JPanel panel = new JPanel(layout);
 
layout.addRow("a"); //one lonely button
panel.add(new JButton("JavaLobby"), "a");
 
panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("title"), BorderFactory.createEmptyBorder(0, 6, 6, 6)));
        
JFrame frame = new JFrame();
frame.add(panel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
now change to...
layout.addRow("ab"); //a beside b
panel.add(new JButton("JavaLobby"), "a");
panel.add(new JButton("JavaLobby"), "b");
now change to...
layout.addRow("a"); //a above
layout.addRow("b"); //b below
now change to...
layout.addRow("a..b"); //dots do nothing
now change to...
layout.addRow("a..b"); //the 'c' zone spans the two buttons
layout.addRow("c..c"); //but doesn't change button's pref size
panel.add(new JButton("JavaLobby"), "a");
panel.add(new JButton("JavaLobby"), "b");
panel.add(new JButton("JavaLobby"), "c");
now we're going to add some modifiers to the "c" zone...
layout.addRow("a..b");
layout.addRow("c.>c");
also try modifying the "c" zone using '>', '-', '~', '|', '!', '+', '*', '-~', '*+' to see how the layout reacts when you resize the frame.

Now try for some nice spacers...
layout.addRow("a.2.b");
layout.addRow("....6");
layout.addRow("c*+.c");
Now try using 1, 2, 3, 4 instead of 2 and 5, 6, 7, 8 instead of 6.

but there's no reason you can't go crazy!
layout.addRow("a.444444444.b");
layout.addRow("............8");
layout.addRow("............8");
layout.addRow("............8");
layout.addRow("............8");
layout.addRow("c....*+.....c");
10 . At 4:04 PM on Nov 27, 2007, Jonathan wrote:
  Click to reply to this thread Reply

Re: GUI Layouts for Swing and SWT: Part 3

Thanks, I actually looked at that guide a while ago and found it very confusing but your examples were pretty clear.

It is a pretty neat layout manager and it looks almost as flexible as miglayout (in the 1-2 minutes I spent playing around with it). But there's still a lot of things I prefer in miglayout.

1) Default spacing for components

ZoneLayout doesn't appear to have any default spacing. You always have to specify spacing between components (?). This is one of the things that makes the code for miglayout gui's so simple and elegant.

2) Spacing in general

Since there's no default spacing for rows, it looks like "spacer" rows have to be added all over the place. This appears to make simple layouts complicated and complicated layouts more verbose.

This was my attempt to add a space of 17 pixels between the two rows:

ZoneLayout layout = ZoneLayoutFactory.newZoneLayout();
setLayout(layout);
layout.addRow("a...b");
layout.addRow("17....");
layout.addRow("c*+.c");
add(new JButton("JavaLobby"), "a");
add(new JButton("JavaLobby"), "b");
add(new JButton("JavaLobby"), "c");


whoops.. that's not going to work. Next attempt:

layout.addRow("9....");
layout.addRow("8....");


Oops.. 9 appears to be some sort of reserved character...!

layout.addRow("8....");
layout.addRow("8....");
layout.addRow("1....");


Now the spacing is 36 :( After about 5 minutes of staring at it I consulted the cheatsheet and found out I was doing the spacing completely wrong. It's my fault for not looking there first. There is no way (?) to make a 17 pixel space, but you can make an 18 pixel spacer like this:

layout.addRow("7...."); // really 12 pixels
layout.addRow("6...."); // but this is 6 pixels


That's not really obvious at all, but I understand why they did it that way.

The MigLayout code that does the same thing seems much clearer to me:
setLayout(new MigLayout());
add(new JButton("JavaLobby"));
add(new JButton("JavaLobby"), "wrap 17");
add(new JButton("JavaLobby"), "spanx, push, grow");


If you wanted it to behave exactly like zone layout, you have to remove the default margin and cell gaps by calling the constructor with: "ins 0, gap 0" but for most layouts these defaults are preferred.

3) It simply looks confusing.

One of the reasons I like miglayout is because it makes my GUI code look very simple and elegant (in most cases). If I didn't care about that, I would just use matisse to generate my gui's since it's much faster and easier to use than hand coding them. I don't know, zone layout is borderline confusing unless you're familiar with the layout and spacing symbols, but its growing on me... :)

Hopefully you dont take this as a zonelayout bashing... It's just my honest opinion, but I've also used miglayout quite a bit over the last couple of months so I may be biased.

----------------------
Update
Now that I've been using it a bit more one thing I prefer over MigLayout is the ability to get a zone and modify the properties of it:

layout.getZone("b").setInsets(...);


For example, I was easily able to simulate MigLayout's 'hidemode 3' by doing the following:

comp.setVisible(!comp.isVisible());
if (!comp.isVisible()) {
         layout.getZone("b").setTake(0,1);   // if its not visible, this zone doesn't take up any space
} else {
         layout.getZone("b").setTake(30,1);  // if it is visible, it should take up 30%
}


That's something I feel miglayout is lacking. In miglayout, if you want to modify one "column constraint" of one column, you have to first obtain the column constraints:

String const = (String)layout.getColumnConstraints();

which returns all of the columns constraints..

"[grow 60,fill]30[right]60[grow 40]"

and do some sort of String manipulation to replace or add constraints (which is fairly tricky):

"[grow 50,fill]30[right]60[grow,fill 50]"

Then set all the column constraints again:

layout.setColumnConstraints(newConst);

And then I believe you may have to call revalidate() on the panel.

This is a real pain. Mikael feel free to correct me if I'm wrong :)
11 . At 11:30 AM on Nov 29, 2007, DJDaveMark wrote:
  Click to reply to this thread Reply

Re: GUI Layouts for Swing and SWT: Part 3

It's funny, because everybody has their own 'thing' that they 'prefer', it's why I love Java! Nearly everything you say, I could inverse and make the opposite point for Zonelayout. What I love is that no one's 'right' - it just makes for great discussions :)

That said, 1) I like specifying the exact spacing, but when I'm in design mode I use 2s and 6s without even thinking about it then tweak them later.

& 2) It's not difficult to have exact heights integrated into your own layouts...

layout.addRow("a.h.b");
layout.addRow("....v");
layout.addRow("c*+.c");
panel.add(new JButton("JavaLobby"), "a");
panel.add(new HSpace(31), "h");
panel.add(new JButton("JavaLobby"), "b");
panel.add(new VSpace(17), "v");
panel.add(new JButton("JavaLobby"), "c");
 
public class VSpace extends JLabel{
    protected Dimension prefSize;
    protected VSpace(){}
    public VSpace(int height){
        prefSize = new Dimension(0, height);
    }
    @Override public Dimension getPreferredSize(){
        return prefSize;
    }
}
public class HSpace extends VSpace{
    public HSpace(int width){
        prefSize = new Dimension(width, 0);
    }
}
but I've never had a need for this!

Moreover, I can't see how to easily reorganise with MigLayout like doing this...
layout.addRow("b.h.c"); //move the buttons
layout.addRow("....v");
layout.addRow("a*+.a");
then
layout.addRow("a*+.a"); //inverse layout
layout.addRow("....v");
layout.addRow("b.h.c");
then
layout.addRow("b*+.b"); //move again
layout.addRow("....v");
layout.addRow("c.h.a");
then
layout.addRow("hc*+c"); //indent 'c' button
layout.addRow("a<a.b");
I see MigLayout having the problem HTML had before CSS came along. Moreover, if something at the top of my layout needs to be added last I can do that with ZoneLayout.

3) After some practice, this cryptic 2D text start's looking like a 3D dynamic model

P.S. any one seen the documentaries Terrorstorm or ENDGAME? Their long but just as mind-changing as ZoneLayout
12 . At 6:25 AM on Nov 30, 2007, Mikael Grev DeveloperZone Top 100 wrote:
  Click to reply to this thread Reply

Re: GUI Layouts for Swing and SWT: Part 3

> I see MigLayout having the problem HTML had before CSS came along.

HTML is like the old way when you set the constraints directly on the components with .setXxxSize(). MigLayout is CSS since it connects the component to a design context.

> Moreover, if something at the top of my layout needs to be added last I can do that with ZoneLayout.

You can do this extremely easy with MigLayout as well.

Cheers,
Mikael Grev (grev at miginfocom dot com)
MiG Java Calendar Component, MiG Layout for Swing/SWT (Vote -> JDK)
13 . At 4:13 AM on Dec 4, 2007, DJDaveMark wrote:
  Click to reply to this thread Reply

Re: GUI Layouts for Swing and SWT: Part 3

Hi Mikael,

Let me be more precise...

With ZoneLayout the 'style' is seperated from the 'markup'
layout.addRow("c*+c"); //the style
panel.add(new JButton("JavaLobby"), "c"); //the markup
but with MigLayout the two are inseparable
panel.add(new JButton("JavaLobby"), "grow, push"); //style & markup
as I mentioned, when I'm changing someone else's layout, with ZoneLayout I don't touch his Java code, but I can play around with the 'style' of the layout till I'm happy.
14 . At 6:26 AM on Dec 4, 2007, Mikael Grev DeveloperZone Top 100 wrote:
  Click to reply to this thread Reply

Re: GUI Layouts for Swing and SWT: Part 3

You just choose to only see it your way.

With MigLayout you can do both:

layout.setComponentConstraint(button, "grow");
panel.add(button);


String buttonLayout = "grow";
panel.add(button, buttonLayout);


Both are even compile time checked and will survive refactoring. You can of course choose not to have that as well.

This is style & markup:

button.setPreferredSize(100, 100);
panel.add(button);



Cheers,
Mikael Grev (grev at miginfocom dot com)
MiG Java Calendar Component, MiG Layout for Swing/SWT (Vote -> JDK)

thread.rss_message