Java Reference
In-Depth Information
{"eight", "hachi"},
{"nine", "kyu"},
{"ten", "ju"}
};
Object columnNames[] = {"English", "Japanese"};
public String getColumnName(int column) {
return columnNames[column].toString();
}
public int getRowCount() {
return rowData.length;
}
public int getColumnCount() {
return columnNames.length;
}
public Object getValueAt(int row, int col) {
return rowData[row][col];
}
};
JTable table = new JTable(model);
JScrollPane scrollPane = new JScrollPane(table);
Specifying Fixed JTable Columns
Now that you've seen the basics of how the TableModel and AbstractTableModel describe the
data, you can create a JTable with some columns that are fixed columns and some that are not.
To create columns that don't scroll, you need to place a second table in the row header view of
the JScrollPane . Then when the user scrolls the table vertically, the two tables will remain in
sync. The two tables then need to share their ListSelectionModel . That way, when a row in one
table is selected, the row in the other table will automatically be selected. Figure 18-9 shows a
table with one fixed column and four scrolling columns.
&IXED#OLUMN 3CROLLABLE#OLUMNS
Figure 18-9. Fixed-column JTable
The source code used to generate Figure 18-9 is shown in Listing 18-4.
 
Search WWH ::




Custom Search