Java Reference
In-Depth Information
Figure 8-14 displays the getContentPane() and the setLayout() methods for the
BillPayer interface. Line 79 creates a content pane, and line 80 sets BorderLayout as
the layout manager. In line 81, the panel to hold all the rows, named fieldPanel, uses
the GridLayout manager and is set to contain eight rows and one column. In line
82, an instance of the FlowLayout manager is created with left justification and with
pixel settings for the horizontal and vertical placement of the components. The
instance, named rowSetup, then is used in lines 83 through 90 as the layout man-
ager for each row. Line 91 sets the buttonPanel to a centered FlowLayout.
77
public BillPayer ()
78
{
79
Container c = getContentPane () ;
80
c.setLayout (( new BorderLayout ())) ;
81
fieldPanel.setLayout ( new GridLayout ( 8,1 )) ;
82
FlowLayout rowSetup = new FlowLayout ( FlowLayout .LEFT,5,3 ) ;
83
firstRow.setLayout ( rowSetup ) ;
84
secondRow.setLayout ( rowSetup ) ;
85
thirdRow.setLayout ( rowSetup ) ;
86
fourthRow.setLayout ( rowSetup ) ;
87
fifthRow.setLayout ( rowSetup ) ;
88
sixthRow.setLayout ( rowSetup ) ;
89
seventhRow.setLayout ( rowSetup ) ;
90
eighthRow.setLayout ( rowSetup ) ;
91
buttonPanel.setLayout ( new FlowLayout ( FlowLayout .CENTER )) ;
92
}
FIGURE 8-14
The following step enters the code to set the layout managers.
To Set the Layout Managers
1. Enter the code from Figure 8-14, lines 79 through 91.
TextPad displays the setLayout() methods (Figure 8-15). The LEFT and
CENTER attributes specify alignment for FlowLayout.
content pane
assigned
layout
methods
FIGURE 8-15
 
Search WWH ::




Custom Search