首页 > 解决方案 > Javafx Scenebuilder 预览与实际场景不匹配

问题描述

当我在 Scene builder 预览窗口(预览模式下的窗口)选项中预览我的表单时,一切都按照我想要的方式完美布置,并且尺寸合适。当我实际运行程序(实际显示的内容)并单击我的按钮以打开这个新表单时,实际上只有大约 1/4 的标签和按钮被显示,除非我将其设为全屏并且所有内容都远远超过它应该是。无论如何建议解决这个问题?

`

<?import javafx.geometry.*?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" 
minWidth="-Infinity" prefHeight="1080.0" prefWidth="1920.0" 
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" 
fx:controller="sample.Controller">
  <children>
  <VBox layoutY="-5.0" prefHeight="811.0" prefWidth="1058.0" spacing="15.0">
     <children>
        <VBox prefHeight="301.0" prefWidth="488.0" spacing="20.0">
           <children>
              <Label alignment="TOP_CENTER" contentDisplay="CENTER" text="These are the available options for a 7 day cruise">
                 <font>
                    <Font name="System Bold" size="30.0" />
                 </font>
              </Label>
              <RadioButton mnemonicParsing="false" text="Interior room ticket $765" />
              <RadioButton mnemonicParsing="false" text="Ocean view ticket $810" />
              <RadioButton mnemonicParsing="false" text="Balcony ticket $1090" />
              <RadioButton mnemonicParsing="false" text="Suite ticket $1560">
                 <padding>
                    <Insets top="5.0" />
                 </padding>
              </RadioButton>
              <Label text="*Prices shown are prices per person">
                 <font>
                    <Font name="System Bold Italic" size="24.0" />
                 </font>
              </Label>
           </children>
           <padding>
              <Insets top="20.0" />
           </padding>
        </VBox>
        <HBox prefHeight="41.0" prefWidth="1895.0" spacing="30.0">
           <children>
              <CheckBox mnemonicParsing="false" text="VIP discount" />
              <CheckBox mnemonicParsing="false" text="Prepaid gratitude" />
           </children>
        </HBox>
        <Label text="Prepaid activites that can be attended by both guests">
           <font>
              <Font name="System Bold" size="30.0" />
           </font>
           <padding>
              <Insets top="75.0" />
           </padding>
        </Label>
        <HBox prefHeight="314.0" prefWidth="1895.0">
           <children>
              <VBox prefHeight="419.0" prefWidth="922.0" spacing="20.0">
                 <children>
                    <CheckBox mnemonicParsing="false" text="Free Internet" />
                    <CheckBox mnemonicParsing="false" text="Couples massage" />
                    <CheckBox mnemonicParsing="false" text="Horse back riding excursion" />
                    <CheckBox mnemonicParsing="false" text="Fitness Classes" />
                    <CheckBox mnemonicParsing="false" />
                 </children>
              </VBox>
              <VBox prefHeight="477.0" prefWidth="942.0" spacing="20.0">
                 <children>
                    <CheckBox mnemonicParsing="false" />
                    <CheckBox mnemonicParsing="false" />
                    <CheckBox mnemonicParsing="false" text="Casino Games" />
                    <CheckBox mnemonicParsing="false" text="Watch a show at the theatre" />
                    <CheckBox mnemonicParsing="false" text="Game Show" />
                    </children>
                  <padding>
                    <Insets bottom="25.0" />
                 </padding>
              </VBox>
           </children>
        </HBox>
            <Button mnemonicParsing="false" text="Calculate total price" />
         </children>
         <padding>
            <Insets bottom="10.0" left="20.0" />
         </padding>
      </VBox>
   </children>
</AnchorPane>

`

主班

标签: javafxscenebuilder

解决方案


我进去并摆脱了大部分手动尺寸。我还将PrimaryStage宽度设置为 800,高度设置为 700,并且不允许调整大小。测试一下。

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

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<AnchorPane maxHeight="700.0" maxWidth="800.0" minHeight="700.0" minWidth="800.0" prefHeight="700.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
  <children>
  <VBox layoutY="-5.0" spacing="15.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
     <children>
        <VBox maxHeight="-Infinity" spacing="20.0" VBox.vgrow="ALWAYS">
           <children>
              <Label alignment="TOP_CENTER" contentDisplay="CENTER" text="These are the available options for a 7 day cruise">
                 <font>
                    <Font name="System Bold" size="22.0" />
                 </font>
              </Label>
              <RadioButton mnemonicParsing="false" text="Interior room ticket $765">
                     <font>
                        <Font size="18.0" />
                     </font>
                     <padding>
                        <Insets left="10.0" />
                     </padding>
                  </RadioButton>
              <RadioButton mnemonicParsing="false" text="Ocean view ticket $810">
                     <font>
                        <Font size="18.0" />
                     </font>
                     <padding>
                        <Insets left="10.0" />
                     </padding>
                  </RadioButton>
              <RadioButton mnemonicParsing="false" text="Balcony ticket $1090">
                     <font>
                        <Font size="18.0" />
                     </font>
                     <padding>
                        <Insets left="10.0" />
                     </padding>
                  </RadioButton>
              <RadioButton mnemonicParsing="false" text="Suite ticket $1560">
                 <padding>
                    <Insets left="10.0" />
                 </padding>
                     <font>
                        <Font size="18.0" />
                     </font>
              </RadioButton>
           </children>
        </VBox>
            <VBox>
               <children>
              <Label text="*Prices shown are prices per person">
                 <font>
                    <Font name="System Bold Italic" size="16.0" />
                 </font>
              </Label>
              <HBox spacing="30.0">
                 <children>
                    <CheckBox mnemonicParsing="false" text="VIP discount">
                           <font>
                              <Font size="15.0" />
                           </font>
                        </CheckBox>
                    <CheckBox mnemonicParsing="false" text="Prepaid gratitude">
                           <font>
                              <Font size="15.0" />
                           </font>
                        </CheckBox>
                 </children>
                     <padding>
                        <Insets left="10.0" />
                     </padding>
              </HBox>
               </children>
            </VBox>
            <VBox prefHeight="200.0" prefWidth="100.0" spacing="20.0" VBox.vgrow="ALWAYS">
               <children>
              <Label text="Prepaid activites that can be attended by both guests" VBox.vgrow="ALWAYS">
                 <font>
                    <Font name="System Bold" size="22.0" />
                 </font>
              </Label>
              <HBox VBox.vgrow="ALWAYS">
                 <children>
                    <VBox spacing="20.0" HBox.hgrow="ALWAYS">
                       <children>
                          <CheckBox mnemonicParsing="false" text="Free Internet">
                                 <font>
                                    <Font size="15.0" />
                                 </font>
                              </CheckBox>
                          <CheckBox mnemonicParsing="false" text="Couples massage">
                                 <font>
                                    <Font size="15.0" />
                                 </font>
                              </CheckBox>
                          <CheckBox mnemonicParsing="false" text="Horse back riding excursion">
                                 <font>
                                    <Font size="15.0" />
                                 </font>
                              </CheckBox>
                          <CheckBox mnemonicParsing="false" text="Fitness Classes">
                                 <font>
                                    <Font size="15.0" />
                                 </font>
                              </CheckBox>
                          <CheckBox mnemonicParsing="false">
                                 <font>
                                    <Font size="15.0" />
                                 </font>
                              </CheckBox>
                       </children>
                           <padding>
                              <Insets left="10.0" />
                           </padding>
                    </VBox>
                    <VBox spacing="20.0" HBox.hgrow="ALWAYS">
                       <children>
                          <CheckBox mnemonicParsing="false">
                                 <font>
                                    <Font size="15.0" />
                                 </font>
                              </CheckBox>
                          <CheckBox mnemonicParsing="false">
                                 <font>
                                    <Font size="15.0" />
                                 </font>
                              </CheckBox>
                          <CheckBox mnemonicParsing="false" text="Casino Games">
                                 <font>
                                    <Font size="15.0" />
                                 </font>
                              </CheckBox>
                          <CheckBox mnemonicParsing="false" text="Watch a show at the theatre">
                                 <font>
                                    <Font size="15.0" />
                                 </font>
                              </CheckBox>
                          <CheckBox mnemonicParsing="false" text="Game Show">
                                 <font>
                                    <Font size="15.0" />
                                 </font>
                              </CheckBox>
                          </children>
                        <padding>
                          <Insets bottom="25.0" />
                       </padding>
                    </VBox>
                 </children>
              </HBox>
               </children>
               <VBox.margin>
                  <Insets top="30.0" />
               </VBox.margin>
            </VBox>
            <Button mnemonicParsing="false" prefHeight="40.0" text="Calculate total price" />
         </children>
         <padding>
            <Insets bottom="15.0" left="20.0" />
         </padding>
      </VBox>
   </children>
   <padding>
      <Insets top="15.0" />
   </padding>
</AnchorPane>

在此处输入图像描述


推荐阅读