Java Reference
In-Depth Information
With these code changes, the window will be:
We could also see the effect of padding the components out from their preferred size by altering the
button constraints a little:
// Create constraints and add first button
constraints.weightx = constraints.weighty = 10.0;
constraints.fill = constraints.NONE;
constraints.ipadx = 30; // Pad 30 in x
constraints.ipady = 10; // Pad 10 in y
addButton("Press", constraints, gridbag); // Add button to content pane
// Set constraints and add second button
constraints.weightx = 5.0; // Weight half of first
constraints.fill = constraints.BOTH; // Expand to fill space
constraints.ipadx = constraints.ipady = 0; // No padding
constraints.gridwidth = constraints.REMAINDER; // Rest of the row
constraints.gridheight = 2; // Height 2x "Press"
constraints.insets = new Insets(10, 30, 10, 20); // Left 30 & right 20
addButton("GO", constraints, gridbag); // Add button to content pane
// Set constraints and add third button
constraints.gridx = 0; // Begin new row
constraints.fill = constraints.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); // Add button to content pane
Search WWH ::




Custom Search