# Creating Lists

You can add a single list or a multiple list to your layout:

- List. Creates a list box that displays a single column of string items.
- Text List. Creates a list box that displays a single column of string items. Use Text List if you intend to add a large number of items to the list.
- Multiple Column List. Creates a multiple column list with headers. (The class name for the Multiple Column List component is ColumnList.)

To add a list:

1. Click on the List component in the AWT palette folder (or the Text List component in the Additional palette tab).

   Text List is in the Additional palette tab.

2. Click in the cell where you want to place the component.
3. Open the attribute editor by clicking on its button in the toolbar.
4. Type a unique component ID in the name box.
5. Type the name of the list items in the items box in the attribute editor.

For a code example of how to add items to the Multiple Column List component, see Adding Items to Multiple Column List. When looking in the class hierarchy for Multiple Column List, search for ColumnList.

For a list that contains a large number of items, Text List performs better than List. Text List currently has a bug, which shows one more visible row than is set in the visibleRows attribute.

### Special Attributes

`allowMultipleSelection` | Turns the ability to select more than one item in the list on or off.
`items` | Adds strings to the list.
`visibleRows` | Sets the number of rows in the list.

To add a multiple column list:

1. Click on the Multiple Column List component in the Additional palette tab.
2. Click in the cell where you want to place the component.
3. Open the attribute editor by clicking on its button in the toolbar.
4. Type a unique component ID in the name box.
5. Type the titles of the column headers in the headers box. Separate header titles with commas.

To add content to the columns, you must add code to a component's source file. Open the Operations dialog box for the component that will be used to add items to the lists. Add items with the `addItem` method. Code should be added to the body class for the component, not its shadow class.

To specify the alignment of the items in each column, enter l (left), r (right), or c (center) in the formats text box. The first alignment character entered sets the alignment for the first column, the next character added to the text box sets the alignment for the next column. You can also click on the button to the right of the text box to open the Formats dialog box to set the alignment for the contents of each column.

### Special Attributes

`autowidth` | Automatically widens a column to accommodate new data.
`formats` | Sets the left, center, or right alignment of the list for each column. Example: a format value of `lcl` left aligns the list items in columns 1 and 3, while text in column 2 is aligned in the center.
`headers` | Inserts the names of column headers.
`highlightItems` | When set to true, temporarily highlights a row in which you programmatically change the values. Useful for demos or applications where you want to draw attention to the arrival of new information in the list.
`selectable` | Sets items in the list as selectable by users.
`showHeaders` | Determines whether column headers are displayed.
`showHorizontalLines` | Determines whether horizontal lines are displayed between rows.
`showVerticalLines` | Determines whether vertical lines are displayed between columns.
`sortColumns` | Determines whether items in each column are shown in ascending or descending order. A "+" preceding the header name displays items under that header in ascending the order (default). A "-" preceding the header name displays items under that header in descending order.

See also:

  Laying Out the Interface
  Generating Java Source Code
  Adding Operations to Components
  GUI Builder Palette

  Visual Java GUI Builder API Documentation
    Visual Java GUI Builder Runtime Packages
    Class Hierarchy
    Index of All Fields and Methods