3 import java.awt.GridBagConstraints;
4 import java.awt.GridBagLayout;
5 import java.awt.Insets;
7 import javax.swing.JComponent;
8 import javax.swing.JPanel;
11 * Class to make it easier to use GridBagLayout
12 * for a two-column, non-equal-width layout
14 public class GuiGridLayout
16 private GridBagLayout _layout = null;
17 private GridBagConstraints _constraints = null;
18 private JPanel _panel = null;
19 private boolean _allLeft = false;
25 * @param inPanel panel using layout
27 public GuiGridLayout(JPanel inPanel)
34 * @param inPanel panel using layout
35 * @param inAllLeft true to align all elements to left
37 public GuiGridLayout(JPanel inPanel, boolean inAllLeft)
41 _layout = new GridBagLayout();
42 _constraints = new GridBagConstraints();
43 _constraints.weightx = 1.0;
44 _constraints.weighty = 0.0;
45 _constraints.ipadx = 10;
46 _constraints.ipady = 1;
47 _constraints.insets = new Insets(1, 5, 1, 5);
48 // Apply layout to panel
49 _panel.setLayout(_layout);
53 * Add the given component to the grid
54 * @param inComponent component to add
56 public void add(JComponent inComponent)
58 _constraints.gridx = _x;
59 _constraints.gridy = _y;
60 _constraints.weightx = (_x==0?0.5:1.0);
62 _constraints.anchor = ((_x == 0 && !_allLeft)?GridBagConstraints.LINE_END:GridBagConstraints.LINE_START);
63 _layout.setConstraints(inComponent, _constraints);
65 _panel.add(inComponent);
66 // work out next position