Java Reference
In-Depth Information
example, [ 1 ] for more information. Java 6 introduces a group layout that is designed
for use by interactive toolsȌsee Productivity Hint 18.1 .
Figure 2
The Grid Layout
Fortunately, you can create acceptable-looking layouts in nearly all situations by
nesting panels. You give each panel an appropriate layout manager. Panels don' t have
visible borders, so you can use as many panels as you need to organize your
components. Figure 3 shows an example; the keypad from the ATM GUI in Chapter
12 . The keypad buttons are contained in a panel with grid layout. That panel is itself
contained in a larger panel with border layout. The text field is in the northern
position of the larger panel. The following code produces this arrangement:
789
790
JPanel keypadPanel = new JPanel();
keypadPanel.setLayout(new BorderLayout());
buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(4, 3));
buttonPanel.add(button7);
buttonPanel.add(button8);
// . . .
keypadPanel.add(buttonPanel, BorderLayout.CENTER);
JTextField display = new JTextField();
keypadPanel.add(display, BorderLayout.NORTH);
 
Search WWH ::




Custom Search