Java Reference
In-Depth Information
The setVisible Method
Many classes of Swing objects have a setVisible method. The setVisible method takes
one argument of type boolean . If w is an object, such as a JFrame window, that can be dis-
played on the screen, then the call
w.setVisible( true );
will make w visible. The call
w.setVisible( false );
will hide w .
SYNTAX
Object_For_Screen .setVisible( Boolean_Expression );
EXAMPLE (FROM DISPLAY 17.2)
public static void main(String[] args)
{
JFrame firstWindow = new JFrame();
.
.
.
firstWindow.setVisible( true );
}
PITFALL: Forgetting to Program the Close-Window Button
The following lines from Display 17.2 ensure that when the user clicks the close-
window button, nothing happens:
firstWindow.setDefaultCloseOperation(
JFrame.DO_NOTHING_ON_CLOSE);
If you forget to program the close-window button, then the default action is as if you
had set it the following way:
firstWindow.setDefaultCloseOperation(
JFrame.HIDE_ON_CLOSE);
Search WWH ::




Custom Search