Java Reference
In-Depth Information
GridBagConstraints constraints,
GridBagLayout layout,
JFrame window) {
// Create a Border object using a BorderFactory method
Border edge = BorderFactory.createRaisedBevelBorder();
JButton button = new JButton(label);
// Create
a button
button.setBorder(edge);
// Add its
border
layout.setConstraints(button, constraints);
// Set the
constraints
window.getContentPane().add(button);
// Add button to
content pane
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createWindow();
}
});
}
}
TryGridBagLayout.java
The program window looks like that shown in Figure 17-28 .
FIGURE 17-28
As you see, the left button is slightly wider than the right button. This is because the length of the button
label affects the size of the button.
 
 
Search WWH ::




Custom Search