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
|
package gui;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.GridBagConstraints;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import javax.swing.JFrame;
public class monGridBag extends javax.swing.JPanel {
private JPanel jPanel1;
private JPanel jPanel7;
private JPanel jPanel6;
private JPanel jPanel5;
private JPanel jPanel4;
private JPanel jPanel3;
private JPanel jPanel2;
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().add(new monGridBag());
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.pack();
frame.show();
}
public monGridBag() {
super();
initGUI();
}
private void initGUI() {
try {
GridBagLayout thisLayout = new GridBagLayout();
thisLayout.columnWeights = new double[] { 0.1, 0.1, 0.1, 0.1, 0.1 };
thisLayout.columnWidths = new int[] { 7, 7, 7, 7, 7 };
thisLayout.rowWeights = new double[] { 0.1, 0.1, 0.1, 0.1 };
thisLayout.rowHeights = new int[] { 7, 7, 7, 7 };
this.setLayout(thisLayout);
setPreferredSize(new Dimension(400, 300));
{
jPanel1 = new JPanel();
this.add(jPanel1, new GridBagConstraints(0, 0, 1, 2, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0));
jPanel1.setBackground(new java.awt.Color(255, 128, 192));
}
{
jPanel2 = new JPanel();
this.add(jPanel2, new GridBagConstraints(1, 0, 3, 2, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0));
jPanel2.setBackground(new java.awt.Color(255, 128, 64));
}
{
jPanel3 = new JPanel();
this.add(jPanel3, new GridBagConstraints(4, 0, 1, 2, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0));
jPanel3.setBackground(new java.awt.Color(128, 128, 255));
}
{
jPanel4 = new JPanel();
this.add(jPanel4, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0));
jPanel4.setBackground(new java.awt.Color(0, 0, 255));
}
{
jPanel5 = new JPanel();
this.add(jPanel5, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0));
jPanel5.setBackground(new java.awt.Color(255, 255, 0));
}
{
jPanel6 = new JPanel();
this.add(jPanel6, new GridBagConstraints(1, 2, 2, 2, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0));
jPanel6.setBackground(new java.awt.Color(128, 255, 255));
}
{
jPanel7 = new JPanel();
this.add(jPanel7, new GridBagConstraints(3, 2, 2, 2, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0));
jPanel7.setBackground(new java.awt.Color(255, 0, 0));
}
} catch (Exception e) {
e.printStackTrace();
}
}
} |
Partager