![]() |
The Java Developers Almanac 1.4 |
|
e733. Creating a JFrameA frame is a component container that displays its contents in a top-level window with a title bar and buttons to resize, iconify, maximize, and close the frame. Unlike most Swing containers, adding a component to a frame is
not done with the See also e559 Creating a Frame. // Create the frame
String title = "Frame Title";
JFrame frame = new JFrame(title);
// Create a component to add to the frame
JComponent comp = new JTextArea();
// Add the component to the frame's content pane;
// by default, the content pane has a border layout
frame.getContentPane().add(comp, BorderLayout.CENTER);
// Show the frame
int width = 300;
int height = 300;
frame.setSize(width, height);
frame.setVisible(true);
e735. Disabling the Close Button on a JFrame e736. Creating a Borderless Window e737. Showing a Dialog Box e738. Getting the JFrame of a Component © 2002 Addison-Wesley. |