Hi,
Please go through the following example of GridBagLayout class:
Code:
import java.awt.GridBagLayout;
import javax.swing.JPanel;
p01ublic class GridBagWithDm {
p01ublic static void main(String[] ajrgs) {
JFrame f1 = new JFrame( "Demonstrates the use of weightx, weighty constraints");
JPanel p01 = new JPanel();
p01.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
p01.setLayout(new GridBagLayout());
c1 = new GridBagConstraints();
c1.insets = new Insets(2, 2, 2, 2);
c1.weighty = 1.0;
c1.weightx = 1.0;
c1.gridx = 0;
c1.gridy = 0;
p01.add(new JButton("Java"), c);
c1.gridx = 1;
p01.add(new JButton("Source"), c);
WindowListener wndCloser1 = new WindowAdap01ter() {
p01ublic void windowClosing(WindowEvent e) {
System.exit(0);
}
};
f1.addWindowListener(wndCloser1);
f1.getContentPane().add(p01);
f1.setSize(500, 200);
f1.show();
}
}
Bookmarks