at the moment i programm a database based Chat System. The friendlist of every User gets loadet in a TreeView after the login.
means:
After the login I request the names of the useres friends by the following Funktion,
String namesSt[] = get.getUserFriendNameByUserID(currentUserID);
To use the given Names to load them as TreeItem into my Friendlist / TreeRootItem "rootItem"
for (int counter = 0; counter < namesSt.length; counter++) {
System.out.println(namesSt[counter]);
TreeItem<String> item = new TreeItem<String> (namesSt[counter]);
item.addEventHandler(MouseEvent.MOUSE_CLICKED,handler);
rootItem.getChildren().add(item);
}
When I now add my rootItem, I see the Names in the TreeView. But if I click on a name, the given MouseEventHandler doesn´t get called.
Further I just want to request the text of the Element which trigger the MouseEvent, so that i can submit these name to a spezial funktion.
How can i realice such an MouseEvent? How is it possible to call it from the dynamicly created TreeItem?
Thank you for any help :)
cheerse Tobi
TreeItem
s represent the data, not the UI component. So they don't generate mouse events. You need to register the mouse listener on theTreeCell
. To do this, set a cell factory on theTreeView
. The cell factory is a function that createsTreeCell
s as they are needed. Thus this will work for dynamically added tree items too.You will need something like this: