javafx - TableCell css class not updating on scroll in TableView -


i have tableview , trying make when click on row, of rows above change style (turn gray). created custom tablecell, , updateitem method shown below. .row-to-ignore css class has few !important properties.

on each updateitem, check whether row index above or below threshold, , either apply or remove style class.

everything works fine until scroll; when scroll up, gets style applied should. however, when scroll down, random lines have style applied, , others don't.

the odd thing if apply style using setstyle(), works correctly.

custom table cell snippet:

@override protected void updateitem(string cellitem, boolean empty) {     super.updateitem(cellitem, empty);      if (cellitem != null) {         settext(cellitem);          // apply styling depending on whether row selected not-data.         if ((this.gettablerow().getindex()) < mhighlightindex)         {             // apply "ignore" styling.             this.getstyleclass().add("row-to-ignore");         } else {             // remove ignore styling.             this.getstyleclass().remove(".row-to-ignore");         }     } else {         settext("");     } } 

css file:

.row-to-ignore {     -fx-background-color: #e3e4e9 !important;     -fx-text-fill: #b8b8b8 !important; } 

i found answer in post. turns out adding multiple copies of class list style class. removing of copies of class made issue go away.

i changed this:

// apply "ignore" styling. this.getstyleclass().add("row-to-ignore"); 

to this:

// apply "ignore" styling. make sure not add duplicate copies of class style list. if (!this.getstyleclass().contains("row-to-ignore")) {     this.getstyleclass().add("row-to-ignore"); } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -