Java Reference
In-Depth Information
button to content pane
TryGridBagLayout4.java
With these code changes, the window is as shown in Figure 17-31 .
FIGURE 17-31
You could also see the effect of padding the components out from their preferred size by altering the but-
ton constraints a little:
// Set constraints and add first button
constraints.weightx = constraints.weighty = 10.0;
constraints.fill = GridBagConstraints.NONE;
constraints.ipadx = 30; // Pad 30 in x
constraints.ipady = 10; // Pad 10 in y
addButton("Press", constraints, gridbag, aWindow); // Add button to
content pane
// Set constraints and add second button
constraints.weightx = 5.0; // Weight half of
first
constraints.fill = GridBagConstraints.BOTH;
// Expand to fill
space
constraints.ipadx = constraints.ipady = 0; // No padding
constraints.insets = new Insets(10, 30, 10, 20); // Left 30 &
 
 
Search WWH ::




Custom Search