dynamic - How to give an dynamicly loaded TreeViewItem an EventHandler? -
At this time, I mean programm a database based chat system
: after login, By requesting names of user friends, To load the given names as a treeitem in their friend list / tree / rootRootItem "rootItem" When I now add my root item, I see the name in the tree view. But if I click on a name, the mouseover handler is not called. In addition to this, I want to request the text of Element which triggers the mouseover, so that I can submit the name to a particular type of name. Funktion How can I cure such a MouseEvent? How is it possible to call dynamically created triitom? Thanks for any help :) Cheers Toby You'll need something for this: string namesest [] = get.getUserFriendNameByUserID (current user ID);
(int counter = 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); }
Tritum s represents data, not UI components. 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.
TreeView & lt; String & gt; tree view ; // ... treeView.setCellFactory (TV -> gt; tree keel & lt; string & gt; cell = new tree kell & lt; & gt; cell.textproperty () .bind (cell.itemProperty ( ); Cell.addEventHandler (MouseEvent.MOUSE_CLICKED, Event -> {if (! Cell.isEmpty ()) {string value = cell.getitim (); treeIT < ); // if necessary // process ...}}); Return Room;}
Comments
Post a Comment