e966. listening for column-related changes in a jtable component.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 47 行

TXT
47
字号
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 + =
减小字号Ctrl + -
显示快捷键?