| 发表于:2007-01-05 13:57:239楼 得分:0 |
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){ //鼠标点击了某一列的头部相应即可 } } } 有问题咱们再讨论 | | |
|