Java Reference
In-Depth Information
Section 22.8 JTabbedPane
•A JTabbedPane (p. 936) arranges GUI components into layers, of which only one is visible at a
time. Users access each layer by clicking its tab.
Section 22.9 BoxLayout Layout Manager
BoxLayout )p. 939) arranges GUI components left-to-right or top-to-bottom in a container.
• Class Box represents a container with BoxLayout as its default layout manager and provides stat-
ic methods to create a Box with a horizontal or vertical BoxLayout .
Section 22.10 GridBagLayout Layout Manager
GridBagLayout (p. 942) is similar to GridLayout , but each component size can vary.
•A GridBagConstraints object (p. 943) specifies how a component is placed in a GridBagLayout .
Self-Review Exercises
22.1
Fill in the blanks in each of the following statements:
a) The class is used to create a menu object.
b) The method of class JMenu places a separator bar in a menu.
c) JSlider events are handled by the
method of interface
.
d)
The GridBagConstraints instance variable
is set to CENTER by default.
22.2
State whether each of the following is true or false . If false , explain why.
a)
When the programmer creates a JFrame , a minimum of one menu must be created and
added to the JFrame .
b)
The variable fill belongs to the GridBagLayout class.
c)
Drawing on a GUI component is performed with respect to the (0, 0) upper-left corner
coordinate of the component.
d)
The default layout for a Box is BoxLayout .
22.3
Find the error(s) in each of the following and explain how to correct the error(s).
a) JMenubar b;
b) mySlider = JSlider( 1000 , 222 , 100 , 450 );
c) gbc.fill = GridBagConstraints.NORTHWEST ; // set fill
d) // override to paint on a customized Swing component
public void paintcomponent(Graphics g)
{
g.drawString( "HELLO" , 50 , 50 );
}
e) // create a JFrame and display it
JFrame f = new JFrame( "A Window" );
f.setVisible( true );
Answers to Self-Review Exercises
22.1
a) JMenu . b) addSeparator . c) stateChanged , ChangeListener . d) anchor .
22.2
a)
False. A JFrame does not require any menus.
b)
False. The variable fill belongs to the GridBagConstraints class.
c)
True.
d)
True.
22.3
a) JMenubar should be JMenuBar .
 
Search WWH ::




Custom Search