19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

TableModel and DefaultTableModel contain the methods for adding,<br />

updating, and removing table data.<br />

TableModel manages table data. You can add and remove rows<br />

through a TableModel. You can also add a column through a<br />

TableModel. However, you cannot remove a column through a<br />

TableModel. To remove a column from a JTable, you have <strong>to</strong> use a<br />

table column model.<br />

<br />

Table column models manage columns in a table. They can be used<br />

<strong>to</strong> select, add, move, and remove table columns. A table column<br />

model must implement the TableColumnModel interface, which<br />

defines the methods for registering table column model listeners,<br />

and for accessing and manipulating columns, as shown in Figure<br />

40.7.<br />

<br />

DefaultTableColumnModel is a concrete class that implements<br />

TableColumnModel and PropertyChangeListener. The<br />

DefaultTableColumnModel class s<strong>to</strong>res its columns in a vec<strong>to</strong>r and<br />

contains an instance of ListSelectionModel for selecting columns.<br />

«interface»<br />

javax.swing.table.TableColumnModel<br />

+addColumn(aColumn: TableColumn): void<br />

+getColumn(columnIndex: int): TableColumn<br />

+getColumnCount(): int<br />

+getColumnIndex(columnIdentifier:Object): int<br />

+getColumnMargin(): int<br />

+getColumns(): Enumeration<br />

+getColumnSelectionAllowed(): boolean<br />

+getSelectedColumnCount(): int<br />

+getSelectedColumns(): void<br />

+getSelectionModel(): ListSelectionModel<br />

+getTotalColumnWidth(): int<br />

+moveColumn(columnIndex: int, newIndex: int): void<br />

+removeColumn(column: TableColumn): void<br />

+setColumnMargin(newMargin: int): void<br />

+setColumnSelectionAllowed(flag: boolean): void<br />

+setSelectionModel(newModel: ListSelectionModel): void<br />

javax.swing.table.DefaultTableColumnModel<br />

javax.swing.table.TableColumn<br />

Figure 40.7<br />

TableColumnModel manages columns in a table and DefaultTableColumnModel<br />

is a concrete implementation of it.<br />

<br />

The column model deals with all the columns in a table. The<br />

TableColumn class is used <strong>to</strong> model an individual column in the<br />

table. An instance of TableColumn for a specified column can be<br />

obtained using the getColumn(index) method in TableColumnModel or<br />

the getColumn(columnIdentifier) method in JTable.<br />

10

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!