I'm using a
JTable
JTable
jTable1.setCellSelectionEnabled(false);
jTable1.setColumnSelectionEnabled(false);
jTable1.setRowSelectionAllowed(true);
jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
You could simply extend the DefaultTableCellRenderer
and pretend, from the UI's side, that the cell isn't "focused".
I removed the border by using the following renderer:
private static class BorderLessTableCellRenderer extends DefaultTableCellRenderer {
private static final long serialVersionUID = 1L;
public Component getTableCellRendererComponent(
final JTable table,
final Object value,
final boolean isSelected,
final boolean hasFocus,
final int row,
final int col) {
final boolean showFocusedCellBorder = false; // change this to see the behavior change
final Component c = super.getTableCellRendererComponent(
table,
value,
isSelected,
showFocusedCellBorder && hasFocus, // shall obviously always evaluate to false in this example
row,
col
);
return c;
}
}
You can set it on your JTable like this:
table.setDefaultRenderer( Object.class, new BorderLessTableCellRenderer() );
or, for Strings:
table.setDefaultRenderer( String.class, new BorderLessTableCellRenderer() );
It's a bit of an hack in that it's simply reusing the original renderer and pretending that the focused/selected cell isn't but it should get you started.