-1

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

Marc
  • 17
  • 6

1 Answers1

-1

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.

Marc
  • 17
  • 6
  • They're "looked-up colors" defined in `modena.css` (the default user-agent stylesheet since JavaFX 8). See the [JavaFX CSS Reference Guide](https://openjfx.io/javadoc/15/javafx.graphics/javafx/scene/doc-files/cssref.html#typecolor). Looked-up colors allow you to define a sort of "theme" with CSS. Modifying them affects that theme rather than just one specific property of a node. – Slaw Jan 25 '21 at 22:13
  • See also https://stackoverflow.com/questions/62472102/where-can-i-find-a-complete-official-reference-on-javafx-css – James_D Jan 25 '21 at 22:15