Java's Swing Library: Part 2
By Bruce Eckel
Last month, I introduced you to the Swing library and showed you how to create and use components like menus, icons, tool tips, and borders that are enhancements to the Abstract Window Toolkit (AWT). List boxes and combo boxes, on the other hand, work in Swing much as they do in the old AWT, but they also have increased functionality if you need it. In addition, some conveniences have been added; for example, JList has a constructor that takes an array of type String, whereas JComboBox does not.
Listing One shows the basic use of each.
Something else that seems a bit odd at first is that a JList does not automatically provide scrolling, even though that's something you always expect. Adding support for scrolling turns out to be quite easy, as also shown in
Listing One: You simply wrap the JList in a JScrollPane, and all the details are automatically managed for you.
Sliders and Progress Bars
A slider allows the user to input data by moving a point back and forth, which is intuitive in some situations (volume controls, for example).