There is a SplitPane in which I have inserted the TableView. And there are some questions.
1. TableView should adapt to different types of objects (currently 3, I plan more). After switching to one of the tabs in the TreeView, the previous one is generated and the new table is generated on the same TableView. Is this a good decision or is it possible to somehow improve / change it?
2. Coloring lines. I want to fill the lines with the color of only the table that corresponds to only one of my objects. But the "dye" goes to each table and constantly generates an exception of incompatibility of objects. Maybe I make a mistake when implementing a dye?

tableView.setRowFactory(rows -> new TableRow<MyClass>() { @Override protected void updateItem(MyClass item, boolean empty) { TreeItem<String> nValue = (TreeItem<String>) treeView.getSelectionModel().getSelectedItem(); if (nValue.getValue().equals("String")) { if (item != null) { if (!item.isActive()) { setStyle("-fx-background-color: darkorange; -fx-text-background-color: black;"); } else { setStyle("-fx-background-color: white; -fx-text-background-color: black;"); } } } super.updateItem(item, empty); } }); 

3. All the same dye. In theory, it should change the color of the line when you click on it (because item.isActive changes its value when pressed), but this does not happen. and I do not understand a little why this is happening. What is wrong here?

    1 answer 1

    1. TableView must adapt to different types of objects.

    Check this point is not entirely clear.

    UPDATE. Judging by the comment that you have different classes MyClass1, MyClass2, etc., etc., you need

    1. Either select one common from these entities and operate on it (for example, calling SuperMyClass and then setting the TableView object with this class)
    2. Or, for each class, create a separate table that will be parameterized by its class.
    1. But the "dye" goes to each table and constantly generates an exception of incompatibility of objects.

    Give the code, because it is also not entirely clear.

    1. but this does not happen. and I do not understand a little

    The whole point is that in the updateItem(MyClass item, boolean empty) method updateItem(MyClass item, boolean empty) you first need to call super.updateItem(item, empty) , and only then write your logic.

    • 1. I have objects MyClass1, MyClass2, MyClass3. Each has different fields that do not overlap. And for each object, I first clean the table, and then attach a new object to the new one. 2. It follows from the first, in fact. I need the rows to be painted only when I use the MyClass1 object, and this code is executed even when the current table is built under MyClass2. 3. Thank you, I will try now - Lejko7
    • @ Lejko7 cm update - Andrew Bystrov