Class 2 |
Intermediate Java 30-IT-397 |
|
JList
-
If you want to present multiple options to the user, you have a few choices.
-
JRadioButtons are good for short, static lists where the user can only
choose one.
-
JCheckBoxes are similar to JRadioButtons, but the user can choose more
than one.
-
JComboBoxes are better for dynamic data, such as data that comes from a
database.
-
JLists are an alternative to JComboBoxes. JLists generally show more
information and take up more screen real estate. The JList also has
more features, but this makes it equally more complex.
-
The JList gives us two basic options:
-
The old fashioned way: Give it Strings to display, handle the logic of
relating the Strings to objects yourself.
-
This is the easier approach, but is still a bit more complex than it really
could be.
-
The object-oriented way: Give the JList a set of objects, use those objects
directly without ever needing to map Strings to objects.
-
Basically, make use of the toString() method for display purposes.
The JList Component

Created by: Brandan Jones
December 17, 2001