I have JTable
and you want to allow deselecting all rows by clicking in the empty part of the table. So far this is wonderful. However, although I call table.clearSelection();
, the table still shows the border around the previously activated cell (see Cell 5 in the example):
I would also like to get rid of this border (this looks especially out of place on Mac's own appearance, where cells suddenly turn black).
A fully working minimal code example:
public class JTableDeselect extends JFrame {
public JTableDeselect() {
Object rowData[][] = { { "1", "2", "3" }, { "4", "5", "6" } };
Object columnNames[] = { "One", "Two", "Three" };
JTable table = new JTable(rowData, columnNames);
table.setFillsViewportHeight(true);
table.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (table.rowAtPoint(e.getPoint()) == -1) {
table.clearSelection();
}
}
});
add(new JScrollPane(table));
setSize(300, 150);
}
public static void main(String args[]) throws Exception {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
new JTableDeselect().setVisible(true);
}
}
[edit] Tried to add the table.getColumnModel().getSelectionModel().clearSelection();
one mentioned here. But that doesn't help either.
source
share