📄 e966. listening for column-related changes in a jtable component.txt
字号:
Events are fired whenever a column is added, removed, resized, or moved.
table.getColumnModel().addColumnModelListener(
new MyTableColumnModelListener(table));
public class MyTableColumnModelListener implements TableColumnModelListener {
JTable table;
// It is necessary to keep the table since it is not possible
// to determine the table from the event's source
public MyTableColumnModelListener(JTable table) {
this.table = table;
}
public void columnAdded(TableColumnModelEvent e) {
int fromIndex = e.getFromIndex();
int toIndex = e.getToIndex();
// fromIndex and toIndex identify the range of added columns
}
public void columnRemoved(TableColumnModelEvent e) {
int fromIndex = e.getFromIndex();
int toIndex = e.getToIndex();
// fromIndex and toIndex identify the range of removed columns
}
public void columnMoved(TableColumnModelEvent e) {
int fromIndex = e.getFromIndex();
int toIndex = e.getToIndex();
// fromIndex and toIndex identify the range of columns being moved.
// In the case of a user dragging a column, this event is fired as
// the column is being dragged to its new position. Also, if the
// column displaces another during dragging, the fromIndex and
// toIndex show its new position; this new position is only
// temporary until the user stops dragging the column.
}
public void columnMarginChanged(ChangeEvent e) {
// The width of some column has changed.
// The event does not identify which column.
}
public void columnSelectionChanged(ListSelectionEvent e) {
// See e964 Listening for Selection Events in a JTable Component
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -