javafx - controlsfx - CheckTreeView - click on CheckBoxTreeItem graphic node is checking the checkbox

Viewed 47

Tested on:

  • win10 64
  • ControlsFx v11.1.1

When I will add a graphic node (ImageView) into CheckBoxTreeItem it behaves as a checkbox (when clicked on). In the example below, I have added wide icons to showcase the issue. Just click on the empty space between checkbox and value and you will see the checkbox will get checked/unchecked.

enter image description here

I would expect the clicking on the ImageView to just select the row. Just like in this picture: enter image description here

here is a minimalistic code example:

package org.example;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.CheckBoxTreeItem;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
import org.controlsfx.control.CheckTreeView;

public class App extends Application {

public static void main(String[] args) {
    launch(args);
}

@Override
public void start(Stage primaryStage) {

    // prepare icons for the tree items
    ImageView imgIcon1 = new ImageView();
    imgIcon1.setFitWidth(64);
    imgIcon1.setFitHeight(16);

    ImageView imgIcon2 = new ImageView();
    imgIcon2.setFitWidth(64);
    imgIcon2.setFitHeight(16);

    // prepare tree items
    CheckBoxTreeItem<String> root = new CheckBoxTreeItem<>("Root");
    CheckBoxTreeItem<String> item1 = new CheckBoxTreeItem<>("Jonathan", imgIcon1);
    CheckBoxTreeItem<String> item2 = new CheckBoxTreeItem<>("Eugene", imgIcon2);

    // add items to the root
    root.getChildren().add(item1);
    root.getChildren().add(item2);
    root.setExpanded(true);

    // Create the CheckTreeView with the data
    CheckTreeView<String> checkTreeView = new CheckTreeView<>(root);

    // show the scene with the tree
    primaryStage.setScene(new Scene(checkTreeView, 200, 100));
    primaryStage.show();
}
}

Any idea how to change the behavior from checking the checkbox to selecting the row?

0 Answers
Related