jtable默認單擊表頭是沒有什麼反應的
要讓單擊表頭就選中該列也很簡單
[java]
import javax
import javax
import java
public class ColumnSelectableJTable extends JTable {
public ColumnSelectableJTable (Object[][] items
super (items
//設置列選擇模式
setColumnSelectionAllowed (true)
setRowSelectionAllowed (false)
final JTableHeader header = getTableHeader()
//表頭增加監聽
header
public void mouseReleased (MouseEvent e) {
if (! e
clearSelection()
//獲取點擊的列索引
int pick = lumnAtPoint(e
//設置選擇模型
addColumnSelectionInterval (pick
}
})
}
}
From:http://tw.wingwit.com/Article/program/Java/Javascript/201311/25288.html