Java Reference
In-Depth Information
window
aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
BorderLayout border = new BorderLayout();
// Create a
layout manager
Container content = aWindow.getContentPane();
// Get the
content pane
content.setLayout(border);
// Set the container
layout mgr
EtchedBorder edge = new EtchedBorder(EtchedBorder.RAISED); //
Button border
// Now add five JButton components and set their borders
JButton button;
content.add(button = new JButton("EAST"), BorderLayout.EAST);
button.setBorder(edge);
content.add(button = new JButton("WEST"), BorderLayout.WEST);
button.setBorder(edge);
content.add(button = new JButton("NORTH"), BorderLayout.NORTH);
button.setBorder(edge);
content.add(button = new JButton("SOUTH"), BorderLayout.SOUTH);
button.setBorder(edge);
content.add(button = new JButton("CENTER"), BorderLayout.CENTER);
button.setBorder(edge);
aWindow.setVisible(true);
// Display the
window
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createWindow();
}
});
}
}
TryBorderLayout.java
If you compile and execute the example, you see the window shown in Figure 17-19 .
FIGURE 17-19
 
 
Search WWH ::




Custom Search