Reputation: 31948
In the application above I have a tabpane (the one with "age", "gender" and "zipcode") where each tab contains a VBox. The VBox is split in two:
The upper part of the VBox lets you view a list of lists, the lower part of the VBox contains a menu that allows you to change the list of lists.
The button in the lower part of the VBox updates the aforementioned list of lists. I want the upper node in the VBox to be updated anew when the underlying lists are changed.
The relevant code snippet might be
Node createHierarchySplitMenu(HierarchiesFromFile hierarchies, String hierarchyName){
VBox vBox = new VBox();
vBox.getChildren().add(createHierarchyScrollPane(hierarchies, hierarchyName));
vBox.getChildren().add(createHierarchyMenu());
return vBox;
}
When the button in the node in the lower part of the VBox (created by createHierarchyMenu()) I want createHierarchyScrollPane() to be called again to show the new list of lists. How do I do that?
Is there a regular pattern/way of updating one node from another (when they are at the same level.)?
What have you tried? Nothing worth mentioning- I am stuck.
If you need more info, please ask. Didn't want to bog you down with code.
Upvotes: 0
Views: 59
Reputation: 34508
From what I understand the solution can be next:
Create class to handle createHierarchyScrollPane():
private class HierarchyScrollPane extends ScrollPane {
public void update(HierarchiesFromFile hierarchies, String hierarchyName) {
// code from createHierarchyScrollPane() which works with "this" instead of new Scroll Pane
}
}
Pass instance to createHierarchyMenu():
Node createHierarchySplitMenu(HierarchiesFromFile hierarchies, String hierarchyName){
VBox vBox = new VBox();
ScrollPaneUpdate hsp = new HierarchyScrollPane();
hsp.update(hierarchies, hierarchyName);
vBox.getChildren().add(hsp);
vBox.getChildren().add(createHierarchyMenu(hsp));
return vBox;
}
Somewhere in createHierarchyMenu():
public void createHierarchyMenu(final HierarchyScrollPane hsp) {
// ...
Button btnSetMin = new Button("Set Min");
btnSetMinsetOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent t) {
// your code for data update
hsp.update(hierarchies, hierarchyName);
}
});
}
Upvotes: 1