Disable row selection in TableView

BioRoy picture BioRoy · Dec 8, 2014 · Viewed 14.8k times · Source

I have a read-only TableView in JavaFX 8, and I don't want' the users to select rows.
They should still be able to sort the columns and scroll, just not to select any rows.
How can I achieve this?

Answer

BioRoy picture BioRoy · Dec 9, 2014

After a while I found how to solve it so posting it here for future users.
The solution is based on this answer: JavaFX8 - Remove highlighting of selected row

After adding the following lines to your css, selected lines will look exactly as unselected lines, achieving the same effect I wanted in the same place:

.table-row-cell:filled:selected { 
  -fx-background: -fx-control-inner-background ;
  -fx-background-color: -fx-table-cell-border-color, -fx-background ;
  -fx-background-insets: 0, 0 0 1 0 ;
  -fx-table-cell-border-color: derive(-fx-color, 5%);
}
.table-row-cell:odd:filled:selected {
  -fx-background: -fx-control-inner-background-alt ;
}