Java Reference
In-Depth Information
46.
47.
// Listener as internal class
48.
class TransferListener implements ListSelectionListener{
49.
50.
public TransferListener(){}
51.
52.
public void valueChanged(ListSelectionEvent evt){
53.
if (!evt.getValueIsAdjusting())
54.
{
55.
String sel = (String)leftList.getSelectedValue();
56.
if (rightListModel.contains(sel))
57.
{
58.
rightListModel.removeElement(sel);
59.
}
else
60.
{
61.
rightListModel.addElement(sel);
62.
}// ifelse
63.
}// if
64.
}// valueChanged
65.
66.
67.
}// internal class
68.
}
16.3
Tables
Tables are used to display data with a two-dimensional structure. Examples are
price lists, distance tables on maps, address books, etc. In Swing class JTable is
used to visualize tables. As for lists, a model is internally used to handle the data.
If the data are complex or change while the program is running, it advisable to
explicitly define such a table model.
A table consists of cells arranged in a rectangular grid. It is possible to add
headings to every column. JTable s are column -oriented. This means that there
is support for the manipulation of columns (for example swapping two columns
or rendering the column content) but only limited support for row manipulation.
When designing a table one should therefore try to arrange the data in such a way
that a column contains data of the same type (strings, integers, images, etc.).
In the following we show how tables can be used to display static data, how table
models work and how they can be used to dynamically or interactively change data
in a table.
16.3.1
A simple static table
If a table displays data that do not change, then the explicit use of a table model
is not necessary. Instead the data can be passed directly to the table in the
constructor. The data are organized in a two-dimensional array content[][] .
Search WWH ::




Custom Search