Java Reference
In-Depth Information
right 20
constraints.gridwidth = GridBagConstraints.RELATIVE; // Rest of the
row
constraints.gridheight = 2; // Height 2x
"Press"
addButton("GO", constraints, gridbag, aWindow); // Add button to
content pane
// Set constraints and add third button
constraints.gridx = 0; // Begin new row
constraints.fill = GridBagConstraints.NONE;
constraints.ipadx = 30; // Pad component in x
constraints.ipady = 10; // Pad component in y
constraints.gridwidth = 1; // Width as
"Press"
constraints.gridheight = 1; // Height as
"Press"
constraints.insets = new Insets(0, 0, 0, 0); // No insets
addButton("Push", constraints, gridbag, aWindow); // Add button to
content pane
TryGridBagLayout5.java
With the constraints for the buttons as before, the window looks as shown in Figure 17-32 .
FIGURE 17-32
Both the Push and the Press button occupy the same space in the container, but because fill is set to
NONE they are not expanded to fill the space in either direction. The ipadx and ipady constraints specify
by how much the buttons are to be expanded from their preferred size — by 30 pixels on the left and
right and 10 pixels on the top and bottom. The overall arrangement remains the same.
 
 
Search WWH ::




Custom Search