SceneBuilder与JavaFX程序看起来不同?
当我在SceneBuilder上编辑时,程序如下所示 当我运行程序时,它看起来是这样的: 这是我第一次尝试使用FXML,我不知道出了什么问题。我试图回答这个问题,但没有找到解决办法 这是我的FXML代码:SceneBuilder与JavaFX程序看起来不同?,java,user-interface,javafx,fxml,Java,User Interface,Javafx,Fxml,当我在SceneBuilder上编辑时,程序如下所示 当我运行程序时,它看起来是这样的: 这是我第一次尝试使用FXML,我不知道出了什么问题。我试图回答这个问题,但没有找到解决办法 这是我的FXML代码: <?xml version="1.0" encoding="UTF-8"?> <GridPane alignment="center" hgap="10" prefHeight="633.0" prefWidth="869.0" stylesheets="/sample/
<?xml version="1.0" encoding="UTF-8"?>
<GridPane alignment="center" hgap="10" prefHeight="633.0" prefWidth="869.0" stylesheets="/sample/sample.css" vgap="10" xmlns="http://javafx.com/javafx/8.0.76-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<columnConstraints>
<ColumnConstraints />
</columnConstraints>
<rowConstraints>
<RowConstraints />
</rowConstraints>
<children>
<BorderPane prefHeight="662.0" prefWidth="869.0" stylesheets="@sample.css">
<top>
<ImageView fitHeight="173.0" fitWidth="409.0" pickOnBounds="true" preserveRatio="true" BorderPane.alignment="CENTER">
<image>
<Image url="@../../../../../Pictures/title.png" />
</image>
</ImageView>
</top>
<right>
<VBox prefHeight="305.0" prefWidth="105.0" BorderPane.alignment="CENTER">
<children>
<Button mnemonicParsing="false" text="Make a Graph" />
<Button mnemonicParsing="false" text="Save" />
<Button mnemonicParsing="false" text="Delete" />
</children></VBox>
</right>
<center>
<VBox prefHeight="200.0" prefWidth="100.0" BorderPane.alignment="CENTER">
<children>
<Pane prefHeight="41.0" prefWidth="764.0">
<children>
<BorderPane prefHeight="0.0" prefWidth="764.0">
<left>
<ComboBox prefWidth="150.0" promptText="Sort or Filter" BorderPane.alignment="CENTER" />
</left>
<right>
<TextField text="Search" BorderPane.alignment="CENTER" />
</right>
<center>
<StackPane prefHeight="150.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<children>
<HBox disable="true" prefHeight="100.0" prefWidth="200.0">
<children>
<ComboBox prefWidth="150.0" />
<CheckBox mnemonicParsing="false" prefHeight="33.0" prefWidth="120.0" text="Favourties" />
</children>
</HBox>
</children>
</StackPane>
</center>
</BorderPane>
</children></Pane>
<ScrollPane prefHeight="507.0" prefWidth="764.0">
<content>
<GridPane prefHeight="90.0" prefWidth="762.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<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 minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label prefHeight="21.0" prefWidth="61.0" text="Graph" />
<Label text="Description" GridPane.columnIndex="1" />
<Label text="Options" GridPane.columnIndex="2" />
<Label text="Favourites" GridPane.columnIndex="3" />
</children>
</GridPane>
</content>
</ScrollPane>
</children>
</VBox>
</center></BorderPane>
</children>
</GridPane>
抱歉,代码太多了。只是不确定问题出在哪里。您似乎只是将一些布局组合在一起,使UI在SceneBuilder中看起来正确 这种方法很糟糕。通过这种方式,您几乎可以肯定,当调整布局的大小时,它将被弄乱。如果调整了
阶段
的大小,则会根据阶段
的大小将场景
的内容强制调整为适当的大小
您也可以在SceneBuilder中观察该行为,如果您将根节点包装在锚链
中,则将原始根的所有锚链设置为0
,并调整锚链
的大小
您应该了解布局的作用,然后在SceneBuilder中设计UI。一般来说,最好保持场景简单,而不是嵌套过多的布局。在您的案例中,3
窗格
s似乎足够了:
GridPane
作为根目录按钮的VBox
滚动窗格中的网格窗格
GridPane
的布局参数,您可以设计一个具有更好大小调整行为的UI:
您似乎将一些布局组合在一起,使UI在SceneBuilder中看起来正确 这种方法很糟糕。通过这种方式,您几乎可以肯定,当调整布局的大小时,它将被弄乱。如果调整了
阶段
的大小,则会根据阶段
的大小将场景
的内容强制调整为适当的大小
您也可以在SceneBuilder中观察该行为,如果您将根节点包装在锚链
中,则将原始根的所有锚链设置为0
,并调整锚链
的大小
您应该了解布局的作用,然后在SceneBuilder中设计UI。一般来说,最好保持场景简单,而不是嵌套过多的布局。在您的案例中,3
窗格
s似乎足够了:
GridPane
作为根目录按钮的VBox
滚动窗格中的网格窗格
GridPane
的布局参数,您可以设计一个具有更好大小调整行为的UI:
在您的情况下,场景的大小小于GridPane的大小
primaryStage.setScene(new Scene(root, 600, 400));
网格中的窗格大小为
<GridPane alignment="center" hgap="10" prefHeight="633.0" prefWidth="869.0"
在您的情况下,场景的大小小于GridPane的大小
primaryStage.setScene(new Scene(root, 600, 400));
网格中的窗格大小为
<GridPane alignment="center" hgap="10" prefHeight="633.0" prefWidth="869.0"
哇,你真是个英雄!我不知道你能用那样的网格。非常感谢你。200000票:)哇,你真是个英雄!我不知道你能用那样的网格。非常感谢你。20万票:)