Java Reference
In-Depth Information
10.
11.
public
BorderFrame()
12.
{
13.
this
.getContentPane().setLayout(
new
GridLayout(2,2));
14.
BorderPanel borderPanel1 =
new
BorderPanel();
15.
BorderPanel borderPanel2 =
new
BorderPanel();
16.
BorderPanel borderPanel3 =
new
BorderPanel("Panel 3");
17.
BorderPanel borderPanel4 =
new
BorderPanel("Panel 4");
18.
this
.getContentPane().add(borderPanel1);
19.
this
.getContentPane().add(borderPanel2);
20.
this
.getContentPane().add(borderPanel3);
21.
this
.getContentPane().add(borderPanel4);
22.
}
23.
24.
public static void
main(String[] args){
25.
BorderFrame borderFrame =
new
BorderFrame();
26.
borderFrame.showIt("Borders");
27.
28.
}
29.
}
■
16.2
Lists
Lists serve two purposes. They can be used to display text information in rows
and they enable the user to select rows and use the selected information in the
program. The graphical concept of a list should not be confused with the data
structure with the same name. Java contains an implementation of the latter in
the class
LinkedList
. The graphical component for lists is the Swing class
JList
.
The list entries are shown as rows.
Instances of
JList
allow arbitrary
Objects
as list entries. The data are inter-
nally stored in a
ListModel
,aclass we describe in Section 16.2.3. An explicit
use of list models is advisable if the data displayed in a list change as the pro-
gram is running. If the data in the list are fixed, it is not really necessary to use
the model explicitly. An example for this can be found in Section 16.2.1.
JLists
also allow the user to select one or more entries. One can display an image or
augment a text with an icon but the programmer has to specify how the display
should be drawn by implementing a
ListCellRenderer
.Weshall use
Strings
only as list entries, which can be displayed without implementing a user-defined
renderer.
We describe the constructor and some methods of
JList
in the following:
JList()
JList(String[] entries)
void
setListData(String[] entries)
void
setSelectionMode(
int
selectionMode)
Search WWH ::
Custom Search