Java Reference
In-Depth Information
You also can call the method setSize( Dimension ) to set up a
frame's size. Dimension is a class in the java.awt package that
represents the width and height of a user interface component.
Calling the Dimension( int , int ) constructor creates a Dimension
object representing the width and height specified as arguments.
NOTE
Another way to set the size of a frame is to fill the frame with the components it will
contain and then call the frame's pack() method. This resizes the frame based on the
size of the components inside it. If the size of the frame is bigger than it needs to be,
pack() shrinks it to the minimum size required to display the components. If the frame is
too small (or the size has not been set at all), pack() expands it to the required size.
Frames are invisible when they are created. You can make them visible by calling the
frame's setVisible( boolean ) method with the literal true as an argument.
If you want a frame to be displayed when it is created, call one of these methods in the
constructor. You also can leave the frame invisible, requiring any class that uses the
frame to make it visible by calling setVisible(true) . (To hide a frame, call
setVisible(false) .)
When a frame is displayed, the default behavior is for it to be positioned in the upper-left
corner of the computer's desktop. You can specify a different location by calling the
setBounds( int , int , int, int ) method. The first two arguments to this method are
the (x,y) position of the frame's upper-left corner on the desktop. The last two arguments
set the width and height of the frame.
The following class represents a 300
100 frame with “Edit Payroll” in the title bar:
public class Payroll extends javax.swing.JFrame {
public Payroll() {
super(“Edit Payroll”);
setSize(300, 100);
setVisible(true);
×
}
}
Every frame has Maximize, Minimize, and Close buttons on the title bar at the user's
control—the same controls present in the interface of other software running on your
system.
The normal behavior when a frame is closed is for the application to keep running. When
a frame serves as a program's main graphical user interface, this leaves a user with no
way to stop the program.
Search WWH ::




Custom Search