1 | public class HorizontalPanel extends JPanel {↵ | | 1 | public class VerticalPanel extends JPanel {↵
|
2 | private Box subPanel = Box.createHorizontalBox();↵ | | 2 | private Box subPanel = Box.createVerticalBox();↵
|
|
3 | private float verticalAlign;↵ | | 3 | private float horizontalAlign;↵
|
|
4 | private int hgap;↵ | | 4 | private int vgap;↵
|
|
5 | public HorizontalPanel() {↵ | | 5 | public VerticalPanel() {↵
|
6 | this(5, CENTER_ALIGNMENT);↵ | | 6 | this(5, LEFT_ALIGNMENT);↵
|
7 | }↵ | | 7 | }↵
|
|
8 | public HorizontalPanel(Color bk) {↵ | | 8 | public VerticalPanel(Color bkg) {↵
|
9 | this();↵ | | 9 | this();↵
|
10 | subPanel.setBackground(bk);↵ | | 10 | subPanel.setBackground(bkg);↵
|
11 | this.setBackground(bk);↵ | | 11 | this.setBackground(bkg);↵
|
12 | }↵ | | |
|
13 | ↵ | | 12 | }↵
|
| | | 13 | ↵
|
14 | public HorizontalPanel(int hgap, float verticalAlign) {↵ | | 14 | public VerticalPanel(int vgap, float horizontalAlign) {↵
|
15 | super(new BorderLayout());↵ | | 15 | super(new BorderLayout());↵
|
16 | add(subPanel, BorderLayout.WEST);↵ | | 16 | add(subPanel, BorderLayout.NORTH);↵
|
17 | this.hgap = hgap;↵ | | 17 | this.vgap = vgap;↵
|
18 | this.verticalAlign = verticalAlign;↵ | | 18 | this.horizontalAlign = horizontalAlign;↵
|
19 | }↵ | | 19 | }↵
|
|
20 | /*↵ | | 20 | /*↵
|
21 | * (non-Javadoc)↵ | | 21 | * (non-Javadoc)↵
|
22 | * ↵ | | 22 | * ↵
|
23 | * @see java.awt.Container#add(java.awt.Component)↵ | | 23 | * @see java.awt.Container#add(java.awt.Component)↵
|
24 | */↵ | | 24 | */↵
|
25 | public Component add(Component c) {↵ | | 25 | public Component add(Component c) {↵
|
26 | // This won't work right if we remove components. But we don't, so I'm↵ | | 26 | // This won't work right if we remove components. But we don't, so I'm↵
|
27 | // not going to worry about it right now.↵ | | 27 | // not going to worry about it right now.↵
|
28 | if (hgap > 0 && subPanel.getComponentCount() > 0) {↵ | | 28 | if (vgap > 0 && subPanel.getComponentCount() > 0) {↵
|
29 | subPanel.add(Box.createHorizontalStrut(hgap));↵ | | 29 | subPanel.add(Box.createVerticalStrut(vgap));↵
|
30 | }↵ | | 30 | }↵
|
|
31 | if (c instanceof JComponent) {↵ | | 31 | if (c instanceof JComponent) {↵
|
32 | ((JComponent) c).setAlignmentY(verticalAlign);↵ | | 32 | ((JComponent) c).setAlignmentX(horizontalAlign);↵
|
33 | }↵ | | 33 | }↵
|
|
34 | return subPanel.add(c);↵ | | 34 | return subPanel.add(c);↵
|
35 | | | 35 |
|