I have the folloing fxml code which includes grid pane and vbox which includes buttons with its ids
is it possible to bind vbox so that the order of the buttons are resorted based on the fx:id?
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="472.0" prefWidth="698.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/18">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<VBox prefHeight="200.0" prefWidth="100.0" GridPane.columnIndex="1">
<children>
<Button fx:id="1" mnemonicParsing="false" prefHeight="72.0" prefWidth="350.0" text="1" />
<Button fx:id="2" mnemonicParsing="false" prefHeight="72.0" prefWidth="350.0" text="2" />
<Button fx:id="3" mnemonicParsing="false" prefHeight="72.0" prefWidth="350.0" text="3" />
<Button fx:id="4" mnemonicParsing="false" prefHeight="72.0" prefWidth="350.0" text="4" />
<Button fx:id="5" mnemonicParsing="false" prefHeight="72.0" prefWidth="350.0" text="5" />
<Button fx:id="6" mnemonicParsing="false" prefHeight="72.0" prefWidth="350.0" text="6" />
<Button fx:id="7" mnemonicParsing="false" prefHeight="72.0" prefWidth="350.0" text="7" />
</children>
</VBox>
</children>
</GridPane>
The Controller the controller has
@FXML
public void initialize() {
List<Integer> ids = new ArrayList<>(); // resort the childs of vbox based on the list "ids"
}
i want to bind the list of buttons to my "ids" variable which includes the new fx-id`s and if the order of list-elemens changes then the order of list of buttons inside vbox should also be changed
0 Better use TreeMap from SortedMap interface.
getting them after traversing in the order of the id