监听整理----JTable

JTable的监听有以下几种

JTable table = new JTable();

1。选择某一行(当选择这一行时,需要产生某种事件)

t able.getSelectionModel().addListSelectionListener( new  ListSelectionListener()
            
... {
                
public void valueChanged(ListSelectionEvent e)
                
...{
                    
//do you what to do 
                       
            }}
);

 2。选择某一列(当选择这一列时,需要产生某种事件)[ListSelectionListener]

table.getColumnModel().addColumnModelListener(
                
new  TableColumnModelListener()  ... {
                    
public void columnAdded(TableColumnModelEvent e) ...{}
                    
public void columnMarginChanged(ChangeEvent e) ...{
                    }

                    
public void columnMoved(TableColumnModelEvent e) ...{
                    }

                    
public void columnRemoved(TableColumnModelEvent e) ...{
                    }

                    
public void columnSelectionChanged(ListSelectionEvent e) ...{}
);

3.单元格响应事件[TableModelListener此细粒度通知告知侦听器单元格、行或列的哪些具体范围发生了更改]

table.getModel().addTableModelListener( new  TableModelListener()  ... {
            
public void tableChanged(TableModelEvent e) ...{});

 

 

你可能感兴趣的:(jtable)