Java Reference
In-Depth Information
LISTING 3.8
continued
frame.getContentPane().add(primary);
frame.pack();
frame.setVisible( true );
}
}
DISPLAY
Note that the primary panel in the program was not explicitly sized. It sized
itself as needed to accommodate the two panels contained in it. Also note that
the subpanels have a buffer around them through which the blue of the primary
panel can be seen. Such spacing is a function of the layout manager that is used
to govern the container and the characteristics set for the components themselves.
These issues are explored further in later Graphics Track sections.
As you did with the previous example, execute and experiment with this one.
Resize the frame to see the effect on the components. Note that the size of the
subpanels stays fixed, and that the orientation of the two panels changes depend-
ing on the width of the primary panel (which expands as the frame expands).
After you are comfortable with the way the components are laid out relative
to each other, change the background color of all panels to the same color (say,
green) to see how the distinction between panels can be invisible if the interface
is designed accordingly.
VideoNote
Example using
frames and
panels.
SELF-REVIEW QUESTIONS (see answers in Appendix N)
SR 3.41 What is the containment hierarchy of a Java graphical user interface?
SR 3.42 In the NestedPanels program, how many panels are created? What
are the names of the panel variables?
 
Search WWH ::




Custom Search