0

I have a tableview with a column called "Display" that should be automatically updated using a SimpleStringProperty binding.

Here is my code (simplified):

public void setupTable () {
    ...
    TableColumn displayColumn = new TableColumn( "Display" );
    displayColumn.setCellValueFactory (
        new PropertyValueFactory <> ( "Display" )
    );

    ...
} 

public class Track {

    boolean isCurrentTrack = false;
    Integer queueIndex = null;

    private final StringProperty display = new SimpleStringProperty ( null );

    public void setIsCurrentTrack ( boolean isCurrentTrack ) {
        this.isCurrentTrack = isCurrentTrack;
        updateDisplayString();
    }

    public void setQueueIndex ( Integer index ) {
        queueIndex = index;
        updateDisplayString();
    }

    public void updateDisplayString() {
        if ( isCurrentTrack ) {
            display.set( "▶" );
        } else if ( queueIndex != null ) {
            display.set( queueIndex.toString() );
        } else {
            display.set( null );
        }
    }

    public void setDisplay( String newDisplay ) {
        display.set( newDisplay );
    }

    public String getDisplay () {
        return display.get();
    }

    public StringProperty displayProperty () {
        return display;
    }
}

When I call setIsCurrentTrack() or setQueueIndex(), updateDisplayString() is called, display.set() is called, but my table view doesn't update. I have to manually cause an update (by sorting the table, for example) in order to get the StringProperty display to update.

What am I doing wrong here?

Grumblesaurus
  • 3,021
  • 3
  • 31
  • 61

0 Answers0