JavaFX窗口大小小于SceneBuilder

时间:2020-04-04 23:23:47

标签: javafx

好,所以我使用SceneBuilder设计了一个场景,我的问题是,当我运行代码时,窗口远小于SceneBuilder中显示的窗口。

.fxml文件:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Hyperlink?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="480.0" prefWidth="640.0" xmlns="http://javafx.com/fxml" xmlns:fx="http://javafx.com/fxml/1">
   <left>
      <VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" spacing="40.0" style="-fx-background-color: #f2f2f2;">
         <children>
            <Label text="Log In">
               <VBox.margin>
                  <Insets />
               </VBox.margin>
               <font>
                  <Font name="System Bold" size="15.199999809265137" />
               </font>
            </Label>
            <Label text="Sign Up">
               <font>
                  <Font name="System Bold" size="15.199999809265137" />
               </font>
            </Label>
         </children>
      </VBox>
   </left>
   <center>
      <VBox id="body" alignment="CENTER" spacing="20.0" stylesheets="@application.css">
         <children>
            <TextField layoutX="110.0" layoutY="165.0" prefHeight="40.0" prefWidth="260.0" promptText="username">
               <opaqueInsets>
                  <Insets />
               </opaqueInsets>
               <VBox.margin>
                  <Insets />
               </VBox.margin>
               <padding>
                  <Insets left="15.0" />
               </padding>
            </TextField>
            <PasswordField prefHeight="40.0" prefWidth="260.0" promptText="password">
               <padding>
                  <Insets left="15.0" />
               </padding>
            </PasswordField>
            <Button alignment="CENTER" mnemonicParsing="false" prefHeight="40.0" prefWidth="290.0" text="LOGIN" />
            <Hyperlink text="Not registered? Create an account " textFill="WHITE">
               <font>
                  <Font size="13.0" />
               </font>
               <VBox.margin>
                  <Insets top="-10.0" />
               </VBox.margin>
            </Hyperlink>
         </children>
         <BorderPane.margin>
            <Insets />
         </BorderPane.margin>
         <padding>
            <Insets left="125.0" right="125.0" />
         </padding></VBox>
   </center>
</BorderPane>

场景创建为:

Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
Scene scene = new Scene(root);

enter image description here

2 个答案:

答案 0 :(得分:1)

在我安装了较新版本的JDK和较新版本的JavaFX之后,该问题不再存在。

答案 1 :(得分:0)

您可以在创建时设置场景大小。

zoom