![]() |
The Java Developers Almanac 1.4 |
|
e622. Creating a GridBagLayoutA gridbag layout is the most sophisticated layout manager in Java's UI toolkit. This example demonstrates how to create and set a gridbag layout and how to set gridbag constraints on components added to the layout. See other examples for code that demonstrates the usage of available gridbag constraints. JFrame frame = new JFrame();
Container container = frame.getContentPane();
// Create the layout
GridBagLayout gbl = new GridBagLayout();
// Set layout on container
container.setLayout(gbl);
// Place a component at cell location (1,1)
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 1;
// Add other gridbag constraints here
// Associate the gridbag constraints with the component
gbl.setConstraints(component, gbc);
// Add the component to the container
container.add(component);
// Show the frame
frame.pack();
frame.setVisible(true);
e624. Getting the Number of Rows and Columns of Cells in a GridBagLayout e625. Making a GridBagLayout Fill the Container e626. Setting the Stretchyness of Rows and Columns in a GridBagLayout Using Layout Weights e627. Setting the Stretchyness of Columns and Rows in a GridBagLayout Using Component Weights e628. Setting the Stretchyness of a Component Within the Cell of a GridBagLayout Using Fill e629. Setting the Location of a Component Within the Cell of a GridBagLayout Using Anchors e630. Setting the Space around a Component Within the Cell of the GridBagLayout Using Insets e631. Adjusting the Size of a Component in a GridBadLayout Using Internal Padding e632. Setting a Row or Column of a GridBadLayout to a Particular Size e633. Setting Gap Sizes in a GridBadLayout
© 2002 Addison-Wesley. |