JavaFX – how to add a container in the anchor pane

I have a simple project that contains fxml. XML with a splitter

So fxml is like this:

<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>

What I want is to insert one in the left anchor pane of the splitter using only java code v@R_199_2419 @.

Can you do that?

I'm new to fxml, so any help will be belittled

Thank you first

Solution

Add FX: ID to the anchorpane to operate on:

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

Get it in the controller as a @ fxml member field:

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

And operate it at the desired location (initialize() shown here can be – almost – anywhere else):

public void initialize() {
    V@R_199_2419@ v@R_199_2419@ = new V@R_199_2419@();
    ...
    AnchorPane.setTopAnchor(v@R_199_2419@,10.0); // obvIoUsly provide your own constraints
    leftAnchorPane.getChildren().add(v@R_199_2419@);
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>