該單元格表示該小區已經集中通過以下方法所示:
int row = table.getSelectedRow();
int column = table.getSelectedColumn();
我想要麼可以設置它自己
您可以設置所選單元格和選定的行如下:
table.changeSelection(6, 2, false, false);
ListSelectionModel lsm = table.getSelectionModel();
lsm.setSelectionInterval(3, 6);
或
ListSelectionModel lsm = table.getSelectionModel();
lsm.setSelectionInterval(3, 6);
table.changeSelection(6, 2, false, true);
編輯:
看樣子你需要從適當的選擇模型得到行/列:
int row = table.getSelectionModel().getLeadSelectionIndex();
int column = table.getColumnModel().getSelectionModel().getLeadSelectionIndex();
未經測試,我會建議在在看看['setCellSelectionEnabled'] (http://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html#setCellSelectionEnabled(boolean)) – MadProgrammer
我試過了,不起作用。謝謝你 – danglingPointer
沒有提供你自己的'TableCellRenderer'作爲顯示[這裏]似乎沒有這樣做這個(http://stackoverflow.com/questions/18801137/java-jtable-disable-single-cell-selection -border-highlight) – MadProgrammer