DVL1 dishevelled.org

Skip to: [content] [navigation]

dishevelled.org layout 1.1-SNAPSHOT :: Downloads | Repository | Javadocs | Checkstyle | Test coverage | Changes


dishevelled.org layout provides layout managers for lightweight JFC/Swing components.


LabelFieldLayout is a wrapper around GridBagLayout that simplifies things for the common case of two columns, one of labels and one of fields.

An example:

JPanel panel = new JPanel();
LabelFieldLayout l = new LabelFieldLayout();

panel.add(new JLabel("Label label:"), l.labelLabel());
panel.add(new JLabel("Label field"), l.labelField());

panel.add(new JLabel("Normal label:"), l.normalLabel());
panel.add(new JTextField("Normal field"), l.normalField());

panel.add(Box.createVerticalStrut(12), l.spacing());

panel.add(new JLabel("Wide label"), l.wideLabel());

panel.add(Box.createVerticalStrut(12), l.spacing());

panel.add(new JLabel("Final wide field:"), l.wideLabel());

JList list = new JList(new Object[] { "Final wide field A",
                                      "Final wide field B",
                                      "Final wide field C" });
panel.add(new JScrollPane(list), l.finalWideField());

The final component in a LabelFieldLayout stretches vertically to cover space left at the bottom of its container. It can be either an empty component, such as Box.createGlue(), or a wide field, such as a JList in a JScrollPane:

LabelFieldLayout example

See LabelFieldLayoutExample.java for a complete example.


LabelFieldPanel is a JPanel whose layout manager is an instance of LabelFieldLayout. It contains helper addLabel and addField methods to reduce the lines of code necessary to lay out components. The example code above can be reduced to the following with LabelFieldPanel:

LabelFieldPanel panel = new LabelFieldPanel();
panel.addField("Label label:", "Label field");
panel.addField("Normal label:", new JTextField("Normal field"));
panel.addLabel("Wide label");
panel.addLabel("Final field:");
JList list = new JList(new Object[] { "Final field A",
                                      "Final field B",
                                      "Final field C" });
panel.addFinalField(new JScrollPane(list));

See LabelFieldPanelExample.java for a complete example.


ButtonPanel is a JPanel whose layout manager is an instance of ButtonLayout. It overrides add(JButton) and add(Action) methods to provide appropriate spacing between adjacent buttons and between buttons and the sides of the container.

ButtonPanel buttonPanel = new ButtonPanel();
buttonPanel.add(new JButton("Up"));
buttonPanel.add(new JButton("Down"));
buttonPanel.add(new AbstractAction("Left") { ... });
buttonPanel.add(new AbstractAction("Right") { ... });

ButtonPanel example

See ButtonPanelExample.java for a complete example.


SourceForge.net Logo