|
发表于 2020-5-29 07:45:02
|
显示全部楼层
private Container c;
private JTable table;
private JTableHeader h;
public TestTable() {
super("TestTable");
c = getContentPane();
table = new JTable(new String[][]{{"1", "chenliang", "no"}, {"2", "guoguo", "no"}}, new String[]{"No.", "Name", "Dead"});
h = table.getTableHeader();
h.addMouseListener(this);
c.add(new JScrollPane(table));
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(700, 400);
setVisible(true);
}
public void mouseClicked(MouseEvent e) {
for (int i = 0; i < table.getColumnCount(); i++) {
if(h.columnAtPoint(e.getPoint()) == i){
//鼠标点击了某一列的头部相应即可
}
}
}
有问题咱们再讨论 |
|