0

I have a TreeView of a file hierarchy and I want know when the user clicks on one of the items so that I can open that file in tab. This question has already been asked before, but:

  • it is from 2013, so the answers may be outdated (even though the accepted one isn't)
  • Simply adding a MouseListener is not enough for me, since users should be able to trigger the action using the keyboard as well as with the mouse

The documentation states I should add my listener to a custom TreeCell, but that class provides no listener methods, so I don't know how to go on from there. I am fine with answers that don't use TreeView, if there are any good alternatives.

piegames
  • 975
  • 12
  • 31
  • 1
    “…but that class provides no listener methods…” Actually it does. Have another look at [the documentation](https://openjfx.io/javadoc/13/javafx.controls/javafx/scene/control/TreeCell.html), particularly the “Properties inherited from class javafx.scene.Node” section. See any property names with the word `Mouse` in them? Also, the “Methods inherited from class javafx.scene.Node” section should contain inherited methods whose names start with `addEvent`. – VGR Jan 05 '20 at 22:34
  • You could add a listener to the TreeCells selected Property – Robert Jan 05 '20 at 23:00

0 Answers0