Question

I have an Hbox which contains Vboxes and each Vbox itself contains other Elements which can be added or removed and some control Buttons. Now I want to add or remove those flexible Elements in my Model and I need to know in which Vbox this is happening.

My attempt was to get the Children of the Hbox and check where the Vbox, where something happend/changed, is located in this List. And work with this Index afterwards.

public int getId (Action event){  
  Button button= event.getSource();  
  Vbox vbox= button.getParent();  
  Hbox hbox= vbox.getParent(); 
  hbox.getChildrenUnmodifiable();
  ....//TODO
}

The Problem is that if I Print hbox.getChildrenUnmodifiable(); it shows me that:

[VBox@1402dd44, Separator@4eaff333[styleClass=separator], Grid hgap=0.0, vgap=0.0, alignment=TOP_LEFT]

and after I add an other Vbox it just adds the

Grid hgap=0.0, vgap=0.0, alignment=TOP_LEFT]

part again and again and doesen't show me any more information of the Vboxes which have been added.

I load the Vboxes from an other .fxml file with hbox.getChildren().add(FXMLLoader.load(getClass().getResource("/VBoxElement.fxml")));

Now I wonder if that looks like an proper way to get the Indexnumber of my Vbox where I am working on? And if anyone has any advice how to get a working Index of my Hbox? This is my first JavaFX project and if I miss understood something feel free to correct me.

Was it helpful?

Solution

As James_D sayd:

ObservableList is just a subinterface of java.util.List, so you can just call all the usual methods: indexOf(...), add(..), remove(...), etc – James_D May 14 at 15:41

Thx, worked fine. As I expected it as first but I messed up my fxml structure and my added fxml did not contain a VBox as root element it contained a Grid. The toString() from the Grid produces the Grid hgap=0.0, vgap=0.0, alignment=TOP_LEFT in the output

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top