Java & J2EE Java's Advanced User Interface Components |
Last time, we mastered some basic UI components and worked on how to add them to panels, organize their layout, and manage their events. Having covered all the basic techniques that we値l need to get started with Java interface programming in our first article, Java's Basic User Interface Components, we will move on to some advanced UI components. Today, I値l be covering scrolling lists, scrollbars, and canvases, and their functionality. It is amazing to see how many of complex tasks are simplified with the help of these advanced user interface components. The List Class The list class allows us to create a scrolling list of values. We can enable single or multiple selections using a list. All that the user has to do is double-click on an item to make a selection. A scrolling list is functionally similar to a choice menu in that it lets us pick several options from a list, but scrolling lists differ in two significant ways:
In short, scrolling lists provide a menu of items that can be selected or deselected. Unlike choice menus, scrolling lists are not pop-up menus and can be defined to allow multiple selections. To create a scrolling list, an instance of the List class is created and then we add individual items to that list. To create a scrolling list use, one of the following constructors:
After creating a List object, add items to it using the addItem() method and then add the list itself to the panel that contains it. Here's an example that creates a list five items high that allows multiple selections
blog comments powered by Disqus |