0

I have created two TreeView(side by side) and list of CheckBoxTreeItem are added to both TreeView. There is an use case with which I can move the content(text) from one TreeView to other by click of an button. But after moving the content it should display in green color. On click of a button I am triggering below event to change the content(which I am able to achieve it) but facing difficulty in adding color to the text content after it changes.

Event.fireEvent(selectedNode, new TreeModificationEvent<String>(
                            TreeItem.valueChangedEvent(), selectedNode, "new value"));
//Here selectedNode is a CheckBoxTreeItem 

I was trying to apply below css property but it adds color to entire TreeView

.tree-cell{
-fx-text-fill:red;
}

I want to change color for those CheckBoxTreeItem whose value got changed. Adding the code for one TreeView. Please find below MVE code

          try {
          CheckBoxTreeItem<String> checkBox1 = new CheckBoxTreeItem<>("English");
          CheckBoxTreeItem<String> checkBox2 = new CheckBoxTreeItem<>("Spanish");
          CheckBoxTreeItem<String> checkBox3 = new CheckBoxTreeItem<>("German");
          CheckBoxTreeItem<String> checkBox4 = new CheckBoxTreeItem<>("French");
          Label label = new Label("Select known languages:");
          Font font = Font.font("verdana", FontWeight.BOLD, FontPosture.REGULAR, 12);
          label.setFont(font);
          CheckBoxTreeItem<String> languages = new CheckBoxTreeItem<>("Languages");
          CheckBoxTreeCell<Object> boxTreeCell = new CheckBoxTreeCell<>();
          boxTreeCell.setStyle("-fx-border-color:yellow;");
          languages.setExpanded(true);
          languages.getChildren().addAll(checkBox1, checkBox2, checkBox3, checkBox4);
          TreeView<String> treeView = new TreeView<>();
          treeView.setRoot(languages);
          treeView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
          treeView.setCellFactory(CheckBoxTreeCell.<String>forTreeView());
          treeView.setStyle("-fx-border-color:white;");
          treeView.setBorder(new Border(new BorderStroke(Color.RED, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT)));
          treeView.setMaxHeight(140);
          VBox vBox = new VBox(5);
          vBox.setPadding(new Insets(25, 5, 5, 50));
          vBox.getChildren().addAll(label, treeView);
          Scene scene = new Scene(new Group(vBox), 595, 200, Color.BEIGE);
          primaryStage.setTitle("Check Tree Item");
          primaryStage.setScene(scene);
          primaryStage.show();primaryStage.setScene(scene);
          
    } catch(Exception e) {
        e.printStackTrace();
    }

I am new to javafx, could you please help me to solve this issue?

kleopatra
  • 51,061
  • 28
  • 99
  • 211
Srikant
  • 55
  • 1
  • 9

0 Answers0