Java Reference
In-Depth Information
// Now add six button components
for(int i = 1; i <= 6; ++i)
content.add(new JButton("Press " + i));
// Add a Button to
content pane
aWindow.setVisible(true); // Display the
window
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createWindow();
}
});
}
}
TryFlowLayout.java
The new code that is of interest is in bold .
How It Works
You create a FlowLayout object and make this the layout manager for aWindow by calling setLayout() .
You then add six JButton components of a default size to aWindow in the loop.
If you compile and run the program, you should get a window similar to the one shown in Figure 17-13 .
FIGURE 17-13
 
 
Search WWH ::




Custom Search