Java Reference
In-Depth Information
Manager
method
layoutContainer
to recalculate the layout of the content pane. Notice in
the screen captures of Fig. 12.42 that certain regions in the
BorderLayout
change shape as
JButton
s are
hidden
and displayed in other regions. Try resizing the application window to
see how the various regions resize based on the window's width and height.
For more complex
layouts, group components in
JPanel
s, each with a separate layout manager.
Place the
JPanel
s
on the
JFrame
using either the default
BorderLayout
or some other layout.
1
// Fig. 12.42: BorderLayoutDemo.java
2
// Testing BorderLayoutFrame.
3
import
javax.swing.JFrame;
4
5
public
class
BorderLayoutDemo
6
{
7
public
static
void
main(String[] args)
8
{
9
BorderLayoutFrame borderLayoutFrame =
new
BorderLayoutFrame();
10
borderLayoutFrame.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE
);
11
borderLayoutFrame.setSize(
300
,
200
);
12
borderLayoutFrame.setVisible(
true
);
13
}
14
}
// end class BorderLayoutDemo
horizontal
gap
vertical
gap
Fig. 12.42
|
Testing
BorderLayoutFrame
.