Java Reference
In-Depth Information
public JList()
JList jlist = new JList();
public JList(Object listData[])
String labels[] = { "Chardonnay", "Sauvignon", "Riesling", "Cabernet", "Zinfandel",
"Merlot", "Pinot Noir", "Sauvignon Blanc", "Syrah", "Gewürztraminer"};
JList jlist = new JList(labels);
public JList(Vector listData)
Vector vector = aBufferedImage.getSources();
JList jlist = new JList(vector);
public JList(ListModel model)
ResultSet results = aJDBCStatement.executeQuery("SELECT colName FROM tableName");
DefaultListModel model = new DefaultListModel();
while (result.next())
model.addElement(result.getString(1));
JList jlist = new JList(model);
If you use the no-argument constructor, you can fill in the data later. However, if you use
the array or Vector constructor, you can't alter the contents without changing the whole
model.
Note If you want to display something other than the toString() results of each array element, see the
section “Rendering JList Elements” later in this chapter for details on how to do that.
JList Properties
After creating a JList component, you can modify each of its many properties. Table 13-5
shows the 32 properties of JList .
Table 13-5. JList Properties
Property Name
Data Type
Access
accessibleContext
AccessibleContext
Read-only
anchorSelectionIndex
int
Read-only
cellRenderer
ListCellRenderer
Read-write bound
dragEnabled
boolean
Read-write
firstVisibleIndex
int
Read-only
fixedCellHeight
int
Read-write bound
fixedCellWidth
int
Read-write bound
 
Search WWH ::




Custom Search