Java Reference
In-Depth Information
The following statement adds a button called quitButton to the north portion of a border
layout:
add(quitButton, BorderLayout.NORTH””);
Listing 11.4 contains the application used to produce Figure 11.4.
LISTING 11.4
The Full Text of Border.java
1: import java.awt.*;
2: import java.awt.event.*;
3: import javax.swing.*;
4:
5: public class Border extends JFrame {
6: JButton nButton = new JButton(“North”);
7: JButton sButton = new JButton(“South”);
8: JButton eButton = new JButton(“East”);
9: JButton wButton = new JButton(“West”);
10: JButton cButton = new JButton(“Center”);
11:
12: public Border() {
13: super(“Border”);
14: setSize(240, 280);
15: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
16: setLayout(new BorderLayout());
17: add(nButton, BorderLayout.NORTH);
18: add(sButton, BorderLayout.SOUTH);
19: add(eButton, BorderLayout.EAST);
20: add(wButton, BorderLayout.WEST);
21: add(cButton, BorderLayout.CENTER);
22: }
23:
24: public static void main(String[] arguments) {
25: Border frame = new Border();
26: frame.setVisible(true);
27: }
28: }
Mixing Layout Managers
At this point, you might be wondering how Java's layout managers can be useful for the
graphical user interfaces you want to design. Choosing a layout manager is an experience
akin to Goldilocks checking out the home of the three bears—”This one is too square!
This one is too disorganized! This one is too strange!”
To find the layout that is just right, you often have to combine more than one manager on
the same interface.
 
 
Search WWH ::




Custom Search