当我在“场景生成器”预览窗口(Window in preview mode)选项中预览表单时,所有内容都按照我想要的完美布局,并且尺寸合适。当我实际运行程序(what actually is shown)并单击我的按钮打开此新表单时,除非我将其全屏显示并且所有内容的间隔远大于它,否则实际上仅显示大约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>
`
答案 0 :(得分:0)
我进去了,摆脱了大多数手动尺寸。我还将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>