【问题标题】:JavaFX - How can i add a container in an anchor paneJavaFX - 如何在锚窗格中添加容器
【发布时间】:2013-12-23 01:13:14
【问题描述】:

我有一个简单的项目,它有一个带有拆分器的 fxml。

所以 fxml 是这样的:

<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="accordionproject.FXMLDocumentController">
    <children>
        <SplitPane fx:id="splitPane" dividerPositions="0.29797979797979796" focusTraversable="true" layoutX="60.0" layoutY="14.0" prefHeight="200.0" prefWidth="320.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns:fx="http://javafx.com/fxml">
            <items>
                <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" />
                <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" />
            </items>
        </SplitPane>
    </children>
</AnchorPane>

我想要的是仅使用 java 代码从拆分器的左锚窗格中插入一个 vbox。

这个可以吗?

我是 fxml 的新手,所以任何帮助都将不胜感激。

提前谢谢你。

【问题讨论】:

    标签: java javafx fxml


    【解决方案1】:

    fx:id 添加到您要操作的AnchorPane

    <AnchorPane fx:id="leftAnchorPane" minHeight="0.0" minWidth="0.0"
        prefHeight="160.0" prefWidth="100.0" />
    

    将它作为@FXML 成员字段放入您的控制器中:

    public class FXMLDocumentController
    {
        @FXML private AnchorPane leftAnchorPane;
        ...
    }
    

    并在所需的位置对其进行操作(此处显示的initialize(),几乎可以在其他任何地方):

    public void initialize() {
        VBox vbox = new VBox();
        ...
        AnchorPane.setTopAnchor(vbox, 10.0); // obviously provide your own constraints
        leftAnchorPane.getChildren().add(vbox);
    }
    

    【讨论】:

      猜你喜欢
      • 2014-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-12
      相关资源
      最近更新 更多