I've got a tableview that sets the background of a row based on the value of one of the row's columns. This is working and I'm doing it using a RowFactory as follows:
`
tv.setRowFactory(tv -> new TableRow<ticketRow>()
{
@Override
protected void updateItem(ticketRow p_ticketRow, boolean empty)
{
super.updateItem(p_ticketRow, empty);
if ( p_ticketRow != null )
{
if (!(p_ticketRow.getTBP().trim().equalsIgnoreCase("0.00")))
{
setStyle("-fx-font-size: 18 !important; -fx-background-color: #ffb2b2; -fx-text-fill : #000000; -fx-font-size: 18 !important; -fx-selection-bar: blue !important;");
}
else
{
setStyle( ".tree-table-row-cell:odd {-fx-background-color: #f9f9f9; -fx-text-fill : #000000; -fx-font-size: 18 !important; -fx-selection-bar: blue;}");
}
}
else
{
setStyle( "-fx-font-size: 18 !important; -fx-selection-bar: blue; .tree-table-row-cell:odd {-fx-background-color: #f9f9f9; -fx-text-fill : #000000; -fx-font-size: 18 !important;}; .tree-table-row-cell:even {-fx-background-color: #ffffff; -fx-text-fill : #000000; -fx-font-size: 18 !important;}" ); // -fx-font-size: 18;}" );
}
}
});
`
However, whenever I select a row whose background has been set by the if clause, the selected row color does not display. That row is not highlighting. The background color seems to take precedence.
How can I get the selected row to highlight when it's background has already been set because it met the column value condition?
Thanks
question from:
https://stackoverflow.com/questions/65891795/javafx-programmatically-highlight-selected-tableview-row 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…