我想通过鼠标点击访问我的treeView中的treeItems。我没有问题访问树视图,因为我可以调用treeView.setOnMouseClicked,但treeItem没有该方法。我尝试了一些像试过的EventHandler这样的东西,但无法让它起作用:
TreeItem<String> soc1Root = new TreeItem<String>("Bla - 1");
soc1Root.setExpanded(true);
TreeItem<String> soc1 = new TreeItem<String>("UnderBla - 1");
soc1.setExpanded(true);
soc1Root.getChildren().add(soc1);
TreeItem<String> termisk = new TreeItem<String>("Stuff happen when clicked!");
soc1.getChildren().add(termisk);
socialKval = new TreeView<String>(soc1Root);
pane.setLeft(socialKval);
EventHandler<MouseEvent> mouseEventHandle = (MouseEvent event) -> {
getTermisk(pane);
System.out.println("Termisk - test");
};
termisk.addEventHandler(MouseEvent.MOUSE_CLICKED, mouseEventHandle);
答案 0 :(得分:0)
只需听取选择模型的选定项目:
treeview.getSelectionModel().getSelectedItem();
OR
treeview.getSelectionModel().selectedItemProperty();
快乐编码,
Kalasch