概述
import javax.swing.JTable;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.TableColumnModelEvent;
import javax.swing.event.TableColumnModelListener;
public class Main {
public static void main(String[] argv) throws Exception {
JTable table = new JTable();
table.getColumnModel().addColumnModelListener(new MyTableColumnModelListener(table));
}
}
class MyTableColumnModelListener implements TableColumnModelListener {
JTable table;
public MyTableColumnModelListener(JTable table) {
this.table = table;
}
public void columnAdded(TableColumnModelEvent e) {
int fromIndex = e.getFromIndex();
int toIndex = e.getToIndex();
System.out.println(fromIndex);
System.out.println(toIndex);
}
public void columnRemoved(TableColumnModelEvent e) {
int fromIndex = e.getFromIndex();
int toIndex = e.getToIndex();
System.out.println(fromIndex);
System.out.println(toIndex);
}
public void columnMoved(TableColumnModelEvent e) {
int fromIndex = e.getFromIndex();
int toIndex = e.getToIndex();
System.out.println(fromIndex);
System.out.println(toIndex);
}
public void columnMarginChanged(ChangeEvent e) {
System.out.println(e);
}
public void columnSelectionChanged(ListSelectionEvent e) {
System.out.println(e);
}
}
最后
以上就是背后哈密瓜为你收集整理的java jtable 事件_Java Swing - 如何处理JTable列更改事件的全部内容,希望文章能够帮你解决java jtable 事件_Java Swing - 如何处理JTable列更改事件所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复