Java FX - filling table rows in different colours

后端 未结 1 948
北海茫月
北海茫月 2021-01-27 22:11

I updated my code to show how the whole class look like Still I got some errors can you validate what I need to improve to have it working

Mainly the problem is with fi

相关标签:
1条回答
  • 2021-01-27 22:29

    You need to update the items of Table View by overriding updateItem() method.

    The code is :

      yourColumnBased.setCellFactory(column -> {
            return new TableCell<CarFx, String>() {
                @Override
                protected void updateItem(String item, boolean empty) {
                    super.updateItem(item, empty);
    
                    setText(empty ? "" : getItem().toString());
                    setGraphic(null);
    
                    TableRow<CarFx> currentRow = getTableRow();
    
                    if (!isEmpty()) {
    
                        if(item.equals("assigned")) 
                            currentRow.setStyle("-fx-background-color:blue");
                        else
                            currentRow.setStyle("-fx-background-color:green");
                    }
                }
            };
        });
    
    0 讨论(0)
提交回复
热议问题