1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class AnotherGridBagLayoutPanel extends JPanel {
private GridBagLayout gridBagLayout1 = new GridBagLayout();
private JPanel topLeftPanel = new JPanel();
private JPanel topRightPanel = new JPanel();
private JPanel centerPanel = new JPanel();
private GridBagLayout gridBagLayout2 = new GridBagLayout();
private JPanel jPanel1 = new JPanel();
private JRadioButton jRadioButton1 = new JRadioButton();
private JRadioButton jRadioButton2 = new JRadioButton();
private JPanel jPanel2 = new JPanel();
private JRadioButton jRadioButton3 = new JRadioButton();
private JRadioButton jRadioButton4 = new JRadioButton();
private JButton jButton1 = new JButton();
private JButton jButton2 = new JButton();
private JButton jButton3 = new JButton();
private JButton jButton4 = new JButton();
private JPanel jPanel3 = new JPanel();
private JButton jButton5 = new JButton();
private JButton jButton6 = new JButton();
public AnotherGridBagLayoutPanel() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setSize(new Dimension(640, 480));
this.setLayout(gridBagLayout1);
topLeftPanel.setBorder(BorderFactory.createLineBorder(Color.black, 1));
topRightPanel.setBorder(BorderFactory.createLineBorder(Color.black, 1));
centerPanel.setBorder(BorderFactory.createLineBorder(Color.black, 1));
centerPanel.setLayout(gridBagLayout2);
jPanel1.setPreferredSize(new Dimension(10, 50));
jPanel1.setMinimumSize(new Dimension(10, 50));
jPanel1.setBorder(BorderFactory.createLineBorder(Color.black, 1));
jRadioButton1.setText("jRadioButton1");
jRadioButton2.setText("jRadioButton2");
jPanel2.setMinimumSize(new Dimension(10, 50));
jPanel2.setSize(new Dimension(520, 50));
jPanel2.setBorder(BorderFactory.createLineBorder(Color.black, 1));
jPanel2.setPreferredSize(new Dimension(12, 50));
jRadioButton3.setText("jRadioButton3");
jRadioButton4.setText("jRadioButton4");
jButton1.setText("jButton1");
jButton1.setPreferredSize(new Dimension(125, 22));
jButton2.setText("jButton2");
jButton2.setPreferredSize(new Dimension(125, 22));
jButton3.setText("jButton3");
jButton3.setPreferredSize(new Dimension(125, 22));
jButton4.setText("jButton4");
jButton4.setPreferredSize(new Dimension(125, 22));
jPanel3.setBorder(BorderFactory.createLineBorder(Color.black, 1));
jPanel3.setPreferredSize(new Dimension(12, 50));
jPanel3.setMinimumSize(new Dimension(12, 50));
jButton5.setText("jButton5");
jButton6.setText("jButton6");
this.add(topLeftPanel,
new GridBagConstraints(0, 0, 1, 1, 0.2, 0.5, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5, 5, 5, 5), 0, 0));
this.add(topRightPanel,
new GridBagConstraints(1, 0, GridBagConstraints.REMAINDER,
1, 0.8, 0.5, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5, 5, 5, 5), 0, 0));
centerPanel.add(jPanel1,
new GridBagConstraints(0, 0, 3, 2, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5, 5, 5, 5), 0, 0));
centerPanel.add(jRadioButton1,
new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(5, 5, 0, 10), 0, 0));
centerPanel.add(jRadioButton2,
new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(5, 5, 0, 10), 0, 0));
centerPanel.add(jPanel2,
new GridBagConstraints(0, 2, 3, 2, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(5, 5, 5, 5), 0, 0));
centerPanel.add(jRadioButton3,
new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(5, 5, 0, 10), 0, 0));
centerPanel.add(jRadioButton4,
new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(5, 5, 0, 10), 0, 0));
centerPanel.add(jButton1,
new GridBagConstraints(0, 4, 1, 1, 0.25, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(5, 5, 0, 0), 0, 0));
centerPanel.add(jButton2,
new GridBagConstraints(3, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE,
new Insets(5, 5, 5, 5), 0, 0));
centerPanel.add(jButton3,
new GridBagConstraints(2, 4, 1, 1, 0.25, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(5, 5, 0, 0), 0, 0));
centerPanel.add(jButton4,
new GridBagConstraints(1, 4, 1, 1, 0.25, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(5, 5, 0, 0), 0, 0));
centerPanel.add(jPanel3,
new GridBagConstraints(0, 5, 3, 2, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 5, 5, 5), 0, 0));
centerPanel.add(jButton5,
new GridBagConstraints(3, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 5, 5, 5), 0, 0));
centerPanel.add(jButton6,
new GridBagConstraints(3, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 5, 5, 5), 0, 0));
this.add(centerPanel,
new GridBagConstraints(0, 1, GridBagConstraints.REMAINDER, 1,
0.0, 0.5, GridBagConstraints.CENTER,
GridBagConstraints.BOTH,
new Insets(5, 5, 5, 5), 0, 0));
}
} |
Partager