我正在尝试获取锚定窗格的宽度以进行超越,但无法正常工作
我用这个:
TranslateTransition content =new TranslateTransition(new Duration(350), xd);
TranslateTransition closeContent=new TranslateTransition(new Duration(350), xd);
content.setToX(menuBar.getWidth());
但是我的转换无法正常工作
如果我愿意
content.setToX(150);
工作
有什么方法可以获取anchorPane的宽度吗?
我的fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXHamburger?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<AnchorPane id="AnchorPane" fx:id="menu" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controllers.Controller2">
<children>
<HBox alignment="CENTER_LEFT" prefHeight="50.0" prefWidth="600.0" style="-fx-background-color: #0080ff;" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<JFXHamburger fx:id="hamburger" />
</children>
<padding>
<Insets left="10.0" />
</padding>
</HBox>
<AnchorPane layoutY="50.0" prefHeight="350.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="50.0">
<children>
<StackPane fx:id="stackConsole" layoutY="25.0" prefHeight="325.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<AnchorPane prefHeight="200.0" prefWidth="200.0" fx:id="xd">
<children>
<Button mnemonicParsing="false" text="Button" AnchorPane.leftAnchor="30.0" AnchorPane.topAnchor="50.0" />
</children>
</AnchorPane>
</children>
</StackPane>
</children>
</AnchorPane>
<VBox prefHeight="400.0" prefWidth="100.0" style="-fx-background-color: #c544;" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="0.0">
<children>
<Button mnemonicParsing="false" text="1" />
<Button mnemonicParsing="false" text="2" />
<Button mnemonicParsing="false" text="3" />
</children>
</VBox>
<AnchorPane fx:id="menuBar" layoutY="50.0" prefHeight="350.0" prefWidth="150.0" style="-fx-background-color: #eee;" translateX="-150.0" AnchorPane.bottomAnchor="0.0" AnchorPane.topAnchor="50.0" />
</children>
</AnchorPane>