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
I'll be the first to admit I don't know much about CSS and I'm also just starting to work with JavaFX. In any case, after scouring more Stackoverflow posts I came across a problem/solution similar to mine where the solution was to use -fx-control-inner-background: and -fx-control-inner-background-alt:
I honestly don't know what these are or how they worked but I used them instead of -fx-background-color: and that worked.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.