Java Reference
In-Depth Information
Having seen how it looks now, clearly it would be better if the GO button were the height of Press and
Push combined. To arrange them like this, you need to make the height of the GO button twice that of
the other two buttons. The height of the Press button is 1 by default, so by making the height of the GO
button 2, and resetting the gridheight constraint of the Push button to 1, you should get the desired
result. Modify the code for the second and third buttons to:
// Set constraints and add second button
constraints.weightx = 5.0; // Weight
half of first
constraints.insets = new java.awt.Insets(10, 30, 10, 20); // Left 30
& right 20
constraints.gridwidth = GridBagConstraints.RELATIVE; // Rest of
the row
constraints.gridheight = 2;
// Height 2x
"Press"
addButton("GO", constraints, gridbag); // Add
button to content pane
// Set constraints and add third button
constraints.insets = new java.awt.Insets(0, 0, 0, 0); // No insets
constraints.gridx = 0; // Begin
new row
constraints.gridwidth = 1; // Width as
"Press"
constraints.gridheight = 1;
// Height as
"Press"
addButton("Push", constraints, gridbag); // Add
Search WWH ::




Custom Search