Quantcast
Viewing all articles
Browse latest Browse all 86

Strikethough on table row in javafx

I want to update a row to be strikethrough in a tableview when the user deletes it. I'm somewhat new to javafx and have been searching with no luck.

        donationsTable.setRowFactory(tv -> {            TableRow<Donation> row = new TableRow<Donation>() {                // to force updateItem called                @Override                protected boolean isItemChanged(Donation d,                        Donation d2) {                    return true;                }                @Override                public void updateItem(Donation d, boolean empty) {                    super.updateItem(d, empty) ;                    if (d == null) {                        setStyle("");                    } else if (d.getAction().equals(Donation.DELETE_DONATION)) {                        setStyle("delete-row");                    } else if (d.getAction().equals(Donation.NEW_DONATION)) {                        setStyle("-fx-font-weight: bold;");                    } else {                        setStyle("");                    }                           }            };            row.setOnMouseClicked(event -> {                    deleteDonation.setDisable(false);            });            return row;        });

The bold works for new donations, but I can't get the strikethrough to work. I did see that it needs to be set on the text, not the row so my css is:

.delete-row .text {    -fx-strikethrough: true;}

However, I'm getting a warning: WARNING CSS Error parsing '*{delete-row}: Expected COLON at [1,12]I only have a very basic understanding of css. This is what I have seen in other answers, but I don't understand why it is not working for me.

Any help is much appreciated.

Based on James_D's suggestion, I changed updateItem:

        public void updateItem(Donation d, boolean empty) {                    super.updateItem(d, empty) ;                    PseudoClass delete = PseudoClass.getPseudoClass("delete-row");                    pseudoClassStateChanged(delete, d != null && d.getAction().equals(Donation.DELETE_DONATION));                    PseudoClass add = PseudoClass.getPseudoClass("add-row");                    pseudoClassStateChanged(add, d != null && d.getAction().equals(Donation.NEW_DONATION));                }

css has

.table-row-cell:delete-row .text {    -fx-strikethrough: true;}.table-row-cell:add-row {    -fx-font-weight: bold;}

strikethrough still not working and bold stopped working.


Viewing all articles
Browse latest Browse all 86

Trending Articles