|
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) {
// The mouse clicks the corresponding head of a column
}
}
}
Let ’s discuss again |
|