如何在Javafx和JFXML中绑定Vbox的度假胜地儿童
我有包括网格窗格和Vbox在内的FXML代码,其中包含具有IDS的按钮,
它可以绑定Vbox,以便根据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>
控制器 控制器具有
@FXML
public void initialize() {
List<Integer> ids = new ArrayList<>(); // resort the childs of vbox based on the list "ids"
}
我想将按钮列表绑定到我的“ IDS”变量,该变量包括新的FX-ID,如果列表 - 元素的顺序更改,则还应更改Vbox内部按钮列表的顺序
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
0
更好地使用来自SortedMap接口的treemap。
按照ID的顺序进行遍历后获得它们
0
Better use TreeMap from SortedMap interface.
getting them after traversing in the order of the id