当.fxml不是场景中的根目录时,JavaFX按钮将消失
所以我有这个。fxml:当.fxml不是场景中的根目录时,JavaFX按钮将消失,java,user-interface,javafx,view,fxml,Java,User Interface,Javafx,View,Fxml,所以我有这个。fxml: <StackPane fx:controller="controller.MainController" xmlns:fx="http://javafx.com/fxml"> <Pane fx:id="aDrawPane" prefHeight="8000" prefWidth="10000" minWidth="10000" minHeight="8000"> </Pane> <BorderPane
<StackPane fx:controller="controller.MainController" xmlns:fx="http://javafx.com/fxml">
<Pane fx:id="aDrawPane" prefHeight="8000" prefWidth="10000" minWidth="10000" minHeight="8000">
</Pane>
<BorderPane fx:id="aBorderPane">
<top>
<VBox>
<ToolBar fx:id="aToolBar" orientation="HORIZONTAL">
<HBox fx:id="umlBox">
<Button text="Create" fx:id="createBtn"/>
<Button text="Package" fx:id="packageBtn"/>
<Button text="Edge" fx:id="edgeBtn"/>
<Button text="Draw" fx:id="drawBtn"/>
</HBox>
<HBox fx:id="utilBox">
<Button text="Select" fx:id="selectBtn"/>
<Button text="Move" fx:id="moveBtn"/>
</HBox>
<HBox fx:id="undoBox">
<Button text="Delete" fx:id="deleteBtn"/>
<Button text="Undo" fx:id="undoBtn"/>
<Button text="Redo" fx:id="redoBtn"/>
</HBox>
<HBox fx:id="recognizeBox">
<Button text="Recognize" fx:id="recognizeBtn"/>
</HBox>
</ToolBar>
</VBox>
</top>
<bottom>
<ToolBar>
<Pane HBox.hgrow="ALWAYS" />
<VBox alignment="CENTER">
<Slider fx:id="zoomSlider" min="10" max="200" value="100"/>
<Label text="Zoom"/>
</VBox>
<Pane HBox.hgrow="ALWAYS" />
</ToolBar>
</bottom>
</BorderPane>
<stylesheets>
<URL value="@main.css" />
</stylesheets>
</StackPane>
这样,顶部工具栏中的按钮和底部工具栏中的滑块一样可见和工作
但是,如果我将代码更改为以下内容:
Group root = new Group();
root.getChildren().add(canvasView);
Scene scene = new Scene(root, 1000, 800);
顶部工具栏可见,但按钮不可见且不可单击,底部工具栏完全消失(第一个窗格“aDrawPane”按预期工作)。
当我想将view.fxml放在选项卡中时,遇到了这个问题。
为什么会发生这种情况?如何使工具栏和按钮再次可见?原因是组不会调整其子对象的大小,而是以其首选大小呈现它们 FXML声明窗格应该是
prefHeight="8000" prefWidth="10000" minWidth="10000"
这正是您得到的。原因是组不会调整其子对象的大小,而是以其首选大小呈现它们 FXML声明窗格应该是
prefHeight="8000" prefWidth="10000" minWidth="10000"
这正是你得到的。你有任何理由使用
组而不是laoder作为root返回的StackPane
吗?你有任何理由使用组而不是laoder作为root返回的StackPane
?