dynamic - How to give an dynamicly loaded TreeViewItem an EventHandler? -


At this time, I programm loads into a TreeView after entering every database of a database based chat system.

means:. I requestres the friends using the following Funktion after the login request, string namesSt [] = get.getUserFriendNameByUserID (currentUserID);

In my friendlist / TreeRootItem "rootItem", use the given names to load them as TreeItem

  (for integer counters = 0; Counter & lt; namesSt.length; counter ++) {System.out.println (namesSt [Counter]); TreeItem & LT; String & gt; Item = new tree item & lt; String & gt; (NamesSt [Counter]); Item.addEventHandler (MouseEvent.MOUSE_CLICKED, handler); . RootItem.getChildren () add (item); }  

When I now add my root item, I see the name in the tree view. But if I click on a name, Given this is not called MouseEventHandler.

In addition I want to request the text of the element which speedes MouseEvent so that I can submit these names to a spezial Funktion.

How can I cure such a MouseEvent? How is it possible to call dynamically created triitom?

Thank you for any help :)

cheerse tobi

after "text" item "itemprop =" text ">

triit s represent data, not UI component. So they do not generate mouse events. You must register the mouse listener at TreeCell . To do this, set a cell factory on triview . A cell factory is a function that requires TreeCell s, as they are required. Thus, it will also work for dynamically linked tree items.

You'll need something for this:

  TreeView & lt; String & gt; tree view ; . // ... treeView.setCellFactory (TV - & gt; {TreeCell & lt; string & gt; cell = new TreeCell & lt; & gt; (); cell.textProperty () dam (cell.itemProperty ()); Cell.addEventHandler (MouseEvent.MOUSE_CLICKED, event -> {{string value = cell.getItem (); treeItem & lt; string & gt; treeItem = cell.getTreeItem (); // if needed // process .. .} (Cell.isEmpty ()!)}); Return Room;}  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

c# - NewtonSoft JArray - how to select multiple elements with LINQ -

javascript - amcharts makechart not working -