Layout Managers: BoxLayout and GridBagLayout

Layout Managers BoxLayout and GridBagLayout

In Chapter 11, we introduced three layout managersFlowLayout, BorderLayout and GridLayout. This section presents two additional layout managers (summarized in Fig. 22.15). We discuss these layout managers in the examples that follow.

Figure 22.15. Additional layout managers.

(This item is displayed on page 1033 in the print version)

Layout Manager

Description

BoxLayout

A layout manager that allows GUI components to be arranged left-to-right or top-to-bottom in a container. Class Box declares a container with BoxLayout as its default layout manager and provides static methods to create a Box with a horizontal or vertical BoxLayout.

GridBagLayout

A layout manager similar to GridLayout, but unlike it in that components can vary in size and can be added in any order.

 

BoxLayout Layout Manager

The BoxLayout layout manager (in package javax.swing) arranges GUI components horizontally along a container's x-axis or vertically along its y-axis. The application in Fig. 22.16 and Fig. 22.17 demonstrates BoxLayout and the container class Box that uses BoxLayout as its default layout manager.

Figure 22.16. BoxLayout layout manager.

(This item is displayed on pages 1033 - 1034 in the print version)

 1 // Fig. 22.16: BoxLayoutFrame.java
 2 // Demonstrating BoxLayout.
 3 import java.awt.Dimension;
 4 import javax.swing.JFrame;
 5 import javax.swing.Box;
 6 import javax.swing.JButton;
 7 import javax.swing.BoxLayout;
 8 import javax.swing.JPanel;
 9 import javax.swing.JTabbedPane;
10
11 public class BoxLayoutFrame extends JFrame
12 {
13 // set up GUI
14 public BoxLayoutFrame()
15 {
16 super( "Demonstrating BoxLayout" );
17
18 // create Box containers with BoxLayout
19 Box horizontal1 = Box.createHorizontalBox();
20 Box vertical1 = Box.createVerticalBox(); 
21 Box horizontal2 = Box.createHorizontalBox();
22 Box vertical2 = Box.createVerticalBox(); 
23
24 final int SIZE = 3; // number of buttons on each Box
25
26 // add buttons to Box horizontal1
27 for ( int count = 0; count < SIZE; count++ )
28 horizontal1.add( new JButton( "Button " + count ) );
29
30 // create strut and add buttons to Box vertical1
31 for ( int count = 0; count < SIZE; count++ )
32 {
33 vertical1.add( Box.createVerticalStrut( 25 ) ); 
34 vertical1.add( new JButton( "Button " + count ) );
35 } // end for
36
37 // create horizontal glue and add buttons to Box horizontal2
38 for ( int count = 0; count < SIZE; count++ )
39 {
40 horizontal2.add( Box.createHorizontalGlue() ); 
41 horizontal2.add( new JButton( "Button " + count ) );
42 } // end for
43
44 // create rigid area and add buttons to Box vertical2
45 for ( int count = 0; count < SIZE; count++ )
46 {
47 vertical2.add( Box.createRigidArea( new Dimension( 12, 8 ) ) );
48 vertical2.add( new JButton( "Button " + count ) ); 
49 } // end for
50
51 // create vertical glue and add buttons to panel
52 JPanel panel = new JPanel();
53 panel.setLayout( new BoxLayout( panel, BoxLayout.Y_AXIS ) );
54
55 for ( int count = 0; count < SIZE; count++ )
56 {
57 panel.add( Box.createGlue() ); 
58 panel.add( new JButton( "Button " + count ) );
59 } // end for
60
61 // create a JTabbedPane
62 JTabbedPane tabs = new JTabbedPane( 
63  JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT );
64
65 // place each container on tabbed pane
66 tabs.addTab( "Horizontal Box", horizontal1 );
67 tabs.addTab( "Vertical Box with Struts", vertical1 );
68 tabs.addTab( "Horizontal Box with Glue", horizontal2 );
69 tabs.addTab( "Vertical Box with Rigid Areas", vertical2 );
70 tabs.addTab( "Vertical Box with Glue", panel );
71
72 add( tabs ); // place tabbed pane on frame
73 } // end BoxLayoutFrame constructor
74 } // end class BoxLayoutFrame

Figure 22.17. Test class for BoxLayoutFrame.

(This item is displayed on pages 1035 - 1036 in the print version)

 1 // Fig. 22.17: BoxLayoutDemo.java
 2 // Demonstrating BoxLayout.
 3 import javax.swing.JFrame;
 4
 5 public class BoxLayoutDemo
 6 {
 7 public static void main( String args[] )
 8 {
 9 BoxLayoutFrame boxLayoutFrame = new BoxLayoutFrame();
10 boxLayoutFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
11 boxLayoutFrame.setSize( 400, 220 ); // set frame size
12 boxLayoutFrame.setVisible( true ); // display frame
13 } // end main
14 } // end class BoxLayoutDemo
 

Lines 1922 create Box containers. References horizontal1 and horizontal2 are initialized with static Box method createHorizontalBox, which returns a Box container with a horizontal BoxLayout in which GUI components are arranged left-to-right. Variables vertical1 and vertical2 are initialized with static Box method createVertical Box, which returns references to Box containers with a vertical BoxLayout in which GUI components are arranged top-to-bottom.

The for statement at lines 2728 adds three JButtons to horizontal1. The for statement at lines 3135 adds three JButtons to vertical1. Before adding each button, line 33 adds a vertical strut to the container with static Box method createVerticalStrut. A vertical strut is an invisible GUI component that has a fixed pixel height and is used to guarantee a fixed amount of space between GUI components. The int argument to method createVerticalStrut determines the height of the strut in pixels. When the container is resized, the distance between GUI components separated by struts does not change. Class Box also declares method createHorizontalStrut for horizontal BoxLayouts.

The for statement at lines 3842 adds three JButtons to horizontal2. Before adding each button, line 40 adds horizontal glue to the container with static Box method createHorizontalGlue. Horizontal glue is an invisible GUI component that can be used between fixed-size GUI components to occupy additional space. Normally, extra space appears to the right of the last horizontal GUI component or below the last vertical one in a BoxLayout. Glue allows the extra space to be placed between GUI components. When the container is resized, components separated by glue components remain the same size, but the glue stretches or contracts to occupy the space between them. Class Box also declares method createVerticalGlue for vertical BoxLayouts.

The for statement at lines 4549 adds three JButtons to vertical2. Before each button is added, line 47 adds a rigid area to the container with static Box method createRigidArea. A rigid area is an invisible GUI component that always has a fixed pixel width and height. The argument to method createRigidArea is a Dimension object that specifies the area's width and height.

Lines 5253 create a JPanel object and set its layout to a BoxLayout in the conventional manner, using Container method setLayout. The BoxLayout constructor receives a reference to the container for which it controls the layout and a constant indicating whether the layout is horizontal (BoxLayout.X_AXIS) or vertical (BoxLayout.Y_AXIS).

The for statement at lines 5559 adds three JButtons to panel. Before adding each button, line 57 adds a glue component to the container with static Box method create-Glue. This component expands or contracts based on the size of the Box.

Lines 6263 create a JTabbedPane to display the five containers in this program. The argument JTabbedPane.TOP sent to the constructor indicates that the tabs should appear The argument JTabbedPane.SCROLL_TAB_LAYOUT specifies that the tabs should scroll if there are too many tabs to fit on one line.

The Box containers and the JPanel are attached to the JTabbedPane at lines 6670. Try executing the application. When the window appears, resize the window to see how the glue components, strut components and rigid area affect the layout on each tab.

GridBagLayout Layout Manager

The most complex and most powerful of the predefined layout managers is GridBagLayout (in package java.awt). This layout is similar to GridLayout in that it arranges components in a grid. However, GridBagLayout is more flexible. The components can vary in size (i.e., they can occupy multiple rows and columns) and can be added in any order.

The first step in using GridBagLayout is determining the appearance of the GUI. For this step you need only a piece of paper. Draw the GUI and then draw a grid over it, dividing the components into rows and columns. The initial row and column numbers should be 0, so that the GridBagLayout layout manager can use the row and column number to properly place the components in the grid. Figure 22.18 demonstrates drawing the lines for the rows and columns over a GUI.

Figure 22.18. Designing a GUI that will use GridBagLayout.

A GridBagConstraints object describes how a component is placed in a GridBagLayout. Several GridBagConstraints fields are summarized in Fig. 22.19.

Figure 22.19. GridBagConstraints fields.

(This item is displayed on page 1038 in the print version)

GridBagConstraints field

Description

anchor

Specifies the relative position (NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST, CENTER) of the component in an area that it does not fill.

fill

Resizes the component in specified direction (NONE, HORIZONTAL, VERTICAL, BOTH) when the display area is larger than the component.

gridx

The column in which the component will be placed.

gridy

The row in which the component will be placed.

gridwidth

The number of columns the component occupies.

gridheight

The number of rows the component occupies.

weightx

The amount of extra space to allocate horizontally. The grid slot can become wider when extra space is available.

weighty

The amount of extra space to allocate vertically. The grid slot can become taller when extra space is available.

GridBagConstraints field anchor specifies the relative position of the component in an area that it does not fill. The variable anchor is assigned one of the following GridBagConstraints constants: NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST or CENTER. The default value is CENTER.

GridBagConstraints field fill defines how the component grows if the area in which it can be displayed is larger than the component. The variable fill is assigned one of the following GridBagConstraints constants: NONE, VERTICAL, HORIZONTAL or BOTH. The default value is NONE, which indicates that the component will not grow in either direction. VERTICAL indicates that it will grow vertically. HORIZONTAL indicates that the component will grow horizontally. BOTH indicates that it will grow in both directions.

Variables gridx and gridy specify where the upper-left corner of the component is placed in the grid. Variable gridx corresponds to the column, and variable gridy corresponds to the row. In Fig. 22.18, the JComboBox (displaying "Iron") has a gridx value of 1 and a gridy value of 2.

Variable gridwidth specifies the number of columns a component occupies. The JComboBox occupies two columns. Variable gridheight specifies the number of rows a component occupies. The JTextArea on the left side of Fig. 22.18 occupies three rows.

Variable weightx specifies how to distribute extra horizontal space to grid slots in a GridBagLayout when the container is resized. A zero value indicates that the grid slot does not grow horizontally on its own. However, if the component spans a column containing a component with nonzero weightx value, the component with zero weightx value will grow horizontally in the same proportion as the other component(s) in the same column. This is because each component must be maintained in the same row and column in which it was originally placed.

Variable weighty specifies how to distribute extra vertical space to grid slots in a GridBagLayout when the container is resized. A zero value indicates that the grid slot does not grow vertically on its own. However, if the component spans a row containing a component with nonzero weighty value, the component with zero weighty value grows vertically in the same proportion as the other component(s) in the same row.

In Fig. 22.18, the effects of weighty and weightx cannot easily be seen until the container is resized and additional space becomes available. Components with larger weight values occupy more of the additional space than those with smaller weight values.

Components should be given nonzero positive weight valuesotherwise they will "huddle" together in the middle of the container. Figure 22.20 shows the GUI of Fig. 22.18 with all weights set to zero.

Figure 22.20. GridBagLayout with the weights set to zero.

(This item is displayed on page 1039 in the print version)

The application in Fig. 22.21 and Fig. 22.22 uses the GridBagLayout layout manager to arrange the components of the GUI in Fig. 22.18. The application does nothing except demonstrate how to use GridBagLayout.

Figure 22.21. GridBagLayout layout manager.

(This item is displayed on pages 1039 - 1040 in the print version)

 1 // Fig. 22.21: GridBagFrame.java
 2 // Demonstrating GridBagLayout.
 3 import java.awt.GridBagLayout; 
 4 import java.awt.GridBagConstraints;
 5 import java.awt.Component;
 6 import javax.swing.JFrame;
 7 import javax.swing.JTextArea;
 8 import javax.swing.JTextField;
 9 import javax.swing.JButton;
10 import javax.swing.JComboBox;
11
12 public class GridBagFrame extends JFrame
13 {
14 private GridBagLayout layout; // layout of this frame 
15 private GridBagConstraints constraints; // constraints of this layout
16
17 // set up GUI
18 public GridBagFrame()
19 {
20 super( "GridBagLayout" );
21 layout = new GridBagLayout(); 
22 setLayout( layout ); // set frame layout 
23 constraints = new GridBagConstraints(); // instantiate constraints
24
25 // create GUI components
26 JTextArea textArea1 = new JTextArea( "TextArea1", 5, 10 );
27 JTextArea textArea2 = new JTextArea( "TextArea2", 2, 2 );
28
29 String names[] = { "Iron", "Steel", "Brass" };
30 JComboBox comboBox = new JComboBox( names );
31
32 JTextField textField = new JTextField( "TextField" );
33 JButton button1 = new JButton( "Button 1" );
34 JButton button2 = new JButton( "Button 2" );
35 JButton button3 = new JButton( "Button 3" );
36
37 // weightx and weighty for textArea1 are both 0: the default
38 // anchor for all components is CENTER: the default
39 constraints.fill = GridBagConstraints.BOTH;
40 addComponent( textArea1, 0, 0, 1, 3 ); 
41
42 // weightx and weighty for button1 are both 0: the default
43 constraints.fill = GridBagConstraints.HORIZONTAL;
44 addComponent( button1, 0, 1, 2, 1 ); 
45 
46 // weightx and weighty for comboBox are both 0: the default
47 // fill is HORIZONTAL
48 addComponent( comboBox, 2, 1, 2, 1 );
49 
50 // button2
51 constraints.weightx = 1000; // can grow wider 
52 constraints.weighty = 1 ; // can grow taller
53 constraints.fill = GridBagConstraints.BOTH; 
54 addComponent( button2, 1, 1, 1, 1 ); 
55 
56 // fill is BOTH for button3
57 constraints.weightx = 0; 
58 constraints.weighty = 0; 
59 addComponent( button3, 1, 2, 1, 1 );
60 
61 // weightx and weighty for textField are both 0, fill is BOTH
62 addComponent( textField, 3, 0, 2, 1 );
63 
64 // weightx and weighty for textArea2 are both 0, fill is BOTH
65 addComponent( textArea2, 3, 2, 1, 1 );
66 } // end GridBagFrame constructor
67 
68 // method to set constraints on
69 private void addComponent( Component component,
70 int row, int column, int width, int height )
71 {
72 constraints.gridx = column; // set gridx 
73 constraints.gridy = row; // set gridy 
74 constraints.gridwidth = width; // set gridwidth 
75 constraints.gridheight = height; // set gridheight 
76 layout.setConstraints( component, constraints ); // set constraints
77 add( component ); // add component 
78 } // end method addComponent
79 } // end class GridBagFrame

Figure 22.22. Test class for GridBagFrame.

(This item is displayed on page 1041 in the print version)

 1 // Fig. 22.22: GridBagDemo.java
 2 // Demonstrating GridBagLayout.
 3 import javax.swing.JFrame;
 4
 5 public class GridBagDemo
 6 {
 7 public static void main( String args[] )
 8 {
 9 GridBagFrame gridBagFrame = new GridBagFrame();
10 gridBagFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
11 gridBagFrame.setSize( 300, 150 ); // set frame size
12 gridBagFrame.setVisible( true ); // display frame
13 } // end main
14 } // end class GridBagDemo
 

The GUI consists of three JButtons, two JTextAreas, a JComboBox and a JTextField. The layout manager for the content pane is GridBagLayout. Lines 2122 create the GridBagLayout object and set the layout manager for the JFrame to layout. Line 23 creates the GridBagConstraints object used to determine the location and size of each component in the grid. Lines 2635 create each GUI component that will be added to the content pane.

Lines 3940 configure JTextArea textArea1 and add it to the content pane. The values for weightx and weighty values are not specified in constraints, so each has the value zero by default. Thus, the JTextArea will not resize itself even if space is available. However, it spans multiple rows, so the vertical size is subject to the weighty values of JButtons button2 and button3. When either button is resized vertically based on its weighty value, the JTextArea is also resized.

Line 39 sets variable fill in constraints to GridBagConstraints.BOTH, causing the JTextArea to always fill its entire allocated area in the grid. An anchor value is not specified in constraints, so the default CENTER is used. We do not use variable anchor in this application, so all the components will use the default. Line 40 calls our utility method addComponent (declared at lines 6978). The JTextArea object, the row, the column, the number of columns to span and the number of rows to span are passed as arguments.

JButton button1 is the next component added (lines 4344). By default, the weightx and weighty values are still zero. The fill variable is set to HORIZONTALthe component will always fill its area in the horizontal direction. The vertical direction is not filled. The weighty value is zero, so the button will become taller only if another component in the same row has a nonzero weighty value. JButton button1 is located at row 0, column 1. One row and two columns are occupied.

JComboBox comboBox is the next component added (line 48). By default, the weightx and weighty values are zero, and the fill variable is set to HORIZONTAL. The JComboBox button will grow only in the horizontal direction. Note that the weightx, weighty and fill variables retain the values set in constraints until they are changed. The JComboBox button is placed at row 2, column 1. One row and two columns are occupied.

JButton button2 is the next component added (lines 5154). It is given a weightx value of 1000 and a weighty value of 1. The area occupied by the button is capable of growing in the vertical and horizontal directions. The fill variable is set to BOTH, which specifies that the button will always fill the entire area. When the window is resized, button2 will grow. The button is placed at row 1, column 1. One row and one column are occupied.

JButton button3 is added next (lines 5759). Both the weightx value and weighty value are set to zero, and the value of fill is BOTH. JButton button3 will grow if the window is resizedit is affected by the weight values of button2. Note that the weightx value for button2 is much larger than that for button3. When resizing occurs, button2 will occupy a larger percentage of the new space. The button is placed at row 1, column 2. One row and one column are occupied.

Both the JTextField textField (line 62) and JTextArea textArea2 (line 65) have a weightx value of 0 and a weighty value of 0. The value of fill is BOTH. The JTextField is placed at row 3, column 0, and the JTextArea at row 3, column 2. The JTextField occupies one row and two columns, the JTextArea one row and one column.

Method addComponent's parameters are a Component reference component and integers row, column, width and height. Lines 7273 set the GridBagConstraints variables gridx and gridy. The gridx variable is assigned the column in which the Component will be placed, and the gridy value is assigned the row in which the Component will be placed. Lines 7475 set the GridBagConstraints variables gridwidth and gridheight. The gridwidth variable specifies the number of columns the Component will span in the grid, and the gridheight variable specifies the number of rows the Component will span in the grid. Line 76 sets the GridBagConstraints for a component in the GridBagLayout. Method setConstraints of class GridBagLayout takes a Component argument and a GridBagConstraints argument. Line 77 adds the component to the JFrame.

When you execute this application, try resizing the window to see how the constraints for each GUI component affect its position and size in the window.

GridBagConstraints Constants RELATIVE and REMAINDER

Instead of gridx and gridy, a variation of GridBagLayout uses GridBagConstraints constants RELATIVE and REMAINDER. RELATIVE specifies that the next-to-last component in a particular row should be placed to the right of the previous component in the row. REMAINDER specifies that a component is the last component in a row. Any component that is not the second-to-last or last component on a row must specify values for GridbagConstraints variables gridwidth and gridheight. The application in Fig. 22.23 and Fig. 22.24 arranges components in GridBagLayout, using these constants.

Figure 22.23. GridBagConstraints constants RELATIVE and REMAINDER.

(This item is displayed on pages 1043 - 1044 in the print version)

 1 // Fig. 22.23: GridBagFrame2.java
 2 // Demonstrating GridBagLayout constants.
 3 import java.awt.GridBagLayout;
 4 import java.awt.GridBagConstraints;
 5 import java.awt.Component;
 6 import javax.swing.JFrame;
 7 import javax.swing.JComboBox;
 8 import javax.swing.JTextField;
 9 import javax.swing.JList;
10 import javax.swing.JButton;
11
12 public class GridBagFrame2 extends JFrame
13 {
14 private GridBagLayout layout; // layout of this frame
15 private GridBagConstraints constraints; // constraints of this layout
16
17 // set up GUI
18 public GridBagFrame2()
19 {
20 super( "GridBagLayout" );
21 layout = new GridBagLayout(); 
22 setLayout( layout ); // set frame layout
23 constraints = new GridBagConstraints(); // instantiate constraints
24
25 // create GUI components
26 String metals[] = { "Copper", "Aluminum", "Silver" };
27 JComboBox comboBox = new JComboBox( metals );
28
29 JTextField textField = new JTextField( "TextField" );
30
31 String fonts[] = { "Serif", "Monospaced" };T
32 JList list = new JList( fonts );
33
34 String names[] = { "zero", "one", "two", "three", "four" };
35 JButton buttons[] = new JButton[ names.length ];
36
37 for ( int count = 0; count < buttons.length; count++ )
38 buttons[ count ] = new JButton( names[ count ] );
39
40 // define GUI component constraints for textField
41 constraints.weightx = 1; 
42 constraints.weighty = 1; 
43 constraints.fill = GridBagConstraints.BOTH; 
44 constraints.gridwidth = GridBagConstraints.REMAINDER;
45 addComponent( textField ); 
46
47 // buttons[0] -- weightx and weighty are 1: fill is BOTH
48 constraints.gridwidth = 1; 
49 addComponent( buttons[ 0 ] );
50
51 // buttons[1] -- weightx and weighty are 1: fill is BOTH
52 constraints.gridwidth = GridBagConstraints.RELATIVE;
53 addComponent( buttons[ 1 ] ); 
54
55 // buttons[2] -- weightx and weighty are 1: fill is BOTH
56 constraints.gridwidth = GridBagConstraints.REMAINDER;
57 addComponent( buttons[ 2 ] ); 
58
59 // comboBox -- weightx is 1: fill is BOTH
60 constraints.weighty = 0; 
61 constraints.gridwidth = GridBagConstraints.REMAINDER;
62 addComponent( comboBox ); 
63
64 // buttons[3] -- weightx is 1: fill is BOTH
65 constraints.weighty = 1; 
66 constraints.gridwidth = GridBagConstraints.REMAINDER;
67 addComponent( buttons[ 3 ] ); 
68
69 // buttons[4] -- weightx and weighty are 1: fill is BOTH
70 constraints.gridwidth = GridBagConstraints.RELATIVE;
71 addComponent( buttons[ 4 ] ); 
72
73 // list -- weightx and weighty are 1: fill is BOTH
74 constraints.gridwidth = GridBagConstraints.REMAINDER;
75 addComponent( list ); 
76 } // end GridBagFrame2 constructor
77
78 // add a component to the container
79 private void addComponent( Component component )
80 {
81 layout.setConstraints( component, constraints );
82 add( component ); // add component 
83 } // end method addComponent
84 } // end class GridBagFrame2

Figure 22.24. Test class for GridBagDemo2.

(This item is displayed on page 1045 in the print version)

 1 // Fig. 22.24: GridBagDemo2.java
 2 // Demonstrating GridBagLayout constants.
 3 import javax.swing.JFrame;
 4
 5 public class GridBagDemo2
 6 {
 7 public static void main( String args[] )
 8 {
 9 GridBagFrame2 gridBagFrame = new GridBagFrame2();
10 gridBagFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
11 gridBagFrame.setSize( 300, 200 ); // set frame size
12 gridBagFrame.setVisible( true ); // display frame
13 } // end main
14 } // end class GridBagDemo2
 

Lines 2122 create a GridBagLayout and use it to set the JFrame's layout manager. The components that are placed in GridBagLayout are created in lines 2738they are a JComboBox, a JTextField, a JList and five JButtons.

The JTextField is added first (lines 4145). The weightx and weighty values are set to 1. The fill variable is set to BOTH. Line 44 specifies that the JTextField is the last component on the line. The JTextField is added to the content pane with a call to our utility method addComponent (declared at lines 7983). Method addComponent takes a Component argument and uses GridBagLayout method setConstraints to set the constraints for the Component. Method add attaches the component to the content pane.

JButton buttons[ 0 ] (lines 4849) has weightx and weighty values of 1. The fill variable is BOTH. Because buttons[ 0 ] is not one of the last two components on the row, it is given a gridwidth of 1 and so will occupy one column. The JButton is added to the content pane with a call to utility method addComponent.

JButton buttons[ 1 ] (lines 5253) has weightx and weighty values of 1. The fill variable is BOTH. Line 52 specifies that the JButton is to be placed relative to the previous component. The Button is added to the JFrame with a call to addComponent.

JButton buttons[ 2 ] (lines 5657) has weightx and weighty values of 1. The fill variable is BOTH. This JButton is the last component on the line, so REMAINDER is used. The JButton is added to the content pane with a call to addComponent.

The JComboBox (lines 6062) has a weightx of 1 and a weighty of 0. The JComboBox will not grow in the vertical direction. The JComboBox is the only component on the line, so REMAINDER is used. The JComboBox is added to the content pane with a call to addComponent.

JButton buttons[ 3 ] (lines 6567) has weightx and weighty values of 1. The fill variable is BOTH. This JButton is the only component on the line, so REMAINDER is used. The JButton is added to the content pane with a call to addComponent.

JButton buttons[ 4 ] (lines 7071) has weightx and weighty values of 1. The fill variable is BOTH. This JButton is the next-to-last component on the line, so RELATIVE is used. The JButton is added to the content pane with a call to addComponent.

The JList (lines 7475) has weightx and weighty values of 1. The fill variable is BOTH. The JList is added to the content pane with a call to addComponent.

Introduction to Computers, the Internet and the World Wide Web

Introduction to Java Applications

Introduction to Classes and Objects

Control Statements: Part I

Control Statements: Part 2

Methods: A Deeper Look

Arrays

Classes and Objects: A Deeper Look

Object-Oriented Programming: Inheritance

Object-Oriented Programming: Polymorphism

GUI Components: Part 1

Graphics and Java 2D™

Exception Handling

Files and Streams

Recursion

Searching and Sorting

Data Structures

Generics

Collections

Introduction to Java Applets

Multimedia: Applets and Applications

GUI Components: Part 2

Multithreading

Networking

Accessing Databases with JDBC

Servlets

JavaServer Pages (JSP)

Formatted Output

Strings, Characters and Regular Expressions

Appendix A. Operator Precedence Chart

Appendix B. ASCII Character Set

Appendix C. Keywords and Reserved Words

Appendix D. Primitive Types

Appendix E. (On CD) Number Systems

Appendix F. (On CD) Unicode®

Appendix G. Using the Java API Documentation

Appendix H. (On CD) Creating Documentation with javadoc

Appendix I. (On CD) Bit Manipulation

Appendix J. (On CD) ATM Case Study Code

Appendix K. (On CD) Labeled break and continue Statements

Appendix L. (On CD) UML 2: Additional Diagram Types

Appendix M. (On CD) Design Patterns

Appendix N. Using the Debugger

Inside Back Cover



Java(c) How to Program
Java How to Program (6th Edition) (How to Program (Deitel))
ISBN: 0131483986
EAN: 2147483647
Year: 2003
Pages: 615

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net