Jon Sansoucie
Jon Sansoucie

Reputation: 531

JavaFX TableView background image

Ok, so I have a tableview create in JavaFX and I understand how to format everything about it except for the global background. Basically, I want the tableview to show and the text to be formatted with the colors and such that I used the cellfactories to format them with, but I want the background of the tableview to be an image I have. Is there a way to put a big background image on the tableview itself? I tried making the cell backgrounds transparent and that didn't help either. Here a snippit of my code.

Callback<TableColumn<TransactionWrapper, String>, TableCell<TransactionWrapper, String>> searchHighlight = new Callback<TableColumn<TransactionWrapper, String>, TableCell<TransactionWrapper, String>>()
    {
        @Override
        public TableCell<TransactionWrapper, String> call(
                TableColumn<TransactionWrapper, String> param)
        {
            return new TableCell<TransactionWrapper, String>()
            {
                @Override
                protected void updateItem(String item, boolean empty)
                {
                    if (!empty)
                    {
                        setStyle("-fx-background-color:transparent");
                        setText(item);
                    }
                }
            };
        }
    };

That's the callback I'm using on my cells to format them dynamically.

#transactionList
{
    -fx-background-image: url("file:/C:/Money/images/transactionsBG.jpg");
}

That's the CSS I'm using to style it with an image background. transactionList is the fx id of the tableview. I'm not getting any errors in the stack trace with finding the image or anything like that but the background is just not showing up.

Any help would be appreciated. Thanks all!

Jon

Upvotes: 0

Views: 2841

Answers (1)

Jos&#233; Pereda
Jos&#233; Pereda

Reputation: 45476

To view the image in the background, you need to add this to your CSS file:

.table-row-cell {
  -fx-background-color: transparent;
}

The styling for the cells is not necessary.

Upvotes: 1

Related Questions