我正面临显示问题,在我的场景构建器输出中,在运行程序时看起来与我的实际输出不同。这是一个例子: 左边是来自场景构建器的那个,右边是来自netbeans上运行程序的那个。场景构建器(左图)中的一个基于黑色方块具有相等的边。另一方面,来自netbeans的一个(右图)具有基于黑盒子的不等边。同样清晰可见的是,右图像的尺寸大于左图像。我怎样才能解决这个问题?如何显示正确的图像以使双方相等?为什么在netbeans上运行它时显示不同?
附上你也可以找到fxml代码:
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXPasswordField?>
<?import com.jfoenix.controls.JFXTextField?>
<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
<?import java.lang.String?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane id="AnchorPane" prefHeight="439.0" prefWidth="300.0" styleClass="darkBackground" stylesheets="@../../resources/css/Consolidated.css" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gui.controllers.LoginController">
<children>
<Pane prefHeight="148.0" prefWidth="300.0" styleClass="loginPaneBackground" AnchorPane.bottomAnchor="291.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label fx:id="isConnected" alignment="CENTER" contentDisplay="CENTER" layoutX="25.0" layoutY="96.0" prefHeight="38.0" prefWidth="273.0" stylesheets="@../../resources/css/Consolidated.css" text="Login" textAlignment="CENTER" textFill="WHITE">
<font>
<Font name="Roboto Regular" size="24.0" />
</font>
<styleClass>
<String fx:value="robotBold" />
<String fx:value="loginLabel" />
</styleClass>
</Label>
<ImageView fitHeight="70.0" fitWidth="70.0" layoutX="126.0" layoutY="14.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../resources/imgs/login_img.png" />
</image>
</ImageView>
</children>
</Pane>
<VBox layoutX="6.0" layoutY="173.0" prefHeight="266.0" prefWidth="300.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<children>
<HBox>
<children>
<FontAwesomeIconView fill="WHITE" glyphName="USER" size="30" styleClass="icon_color">
<HBox.margin>
<Insets left="20.0" right="20.0" />
</HBox.margin>
</FontAwesomeIconView>
<JFXTextField fx:id="txtUsername" focusColor="#03a9f4" labelFloat="true" prefHeight="25.0" prefWidth="175.0" promptText="Username" stylesheets="@../../resources/css/Consolidated.css" unFocusColor="#bdbdbd">
<font>
<Font name="Century Gothic" size="12.0" />
</font>
<styleClass>
<String fx:value="txtFields" />
<String fx:value="robotReg" />
</styleClass>
<HBox.margin>
<Insets left="20.0" right="20.0" />
</HBox.margin>
</JFXTextField>
</children>
<VBox.margin>
<Insets bottom="10.0" left="20.0" right="20.0" top="10.0" />
</VBox.margin>
</HBox>
<HBox>
<children>
<FontAwesomeIconView fill="WHITE" glyphName="LOCK" size="30" styleClass="icon_color">
<HBox.margin>
<Insets left="20.0" right="20.0" />
</HBox.margin>
</FontAwesomeIconView>
<JFXPasswordField fx:id="txtPassword" focusColor="#03a9f4" labelFloat="true" prefHeight="23.0" prefWidth="175.0" promptText="Password" stylesheets="@../../resources/css/Consolidated.css" unFocusColor="#bdbdbd">
<font>
<Font name="Century Gothic Bold" size="12.0" />
</font>
<HBox.margin>
<Insets left="25.0" right="20.0" />
</HBox.margin>
<styleClass>
<String fx:value="txtFields" />
<String fx:value="robotReg" />
</styleClass>
</JFXPasswordField>
</children>
<VBox.margin>
<Insets bottom="10.0" left="20.0" right="20.0" top="10.0" />
</VBox.margin>
</HBox>
<HBox>
<children>
<FontAwesomeIconView fill="WHITE" glyphName="GEAR" size="30" styleClass="icon_color">
<HBox.margin>
<Insets left="18.0" right="20.0" />
</HBox.margin>
</FontAwesomeIconView>
<ComboBox fx:id="comboType" prefHeight="27.0" prefWidth="175.0" promptText="Type" stylesheets="@../../resources/css/Consolidated.css">
<styleClass>
<String fx:value="comboBox" />
<String fx:value="robotReg" />
</styleClass>
<opaqueInsets>
<Insets />
</opaqueInsets>
<HBox.margin>
<Insets left="20.0" right="20.0" />
</HBox.margin>
<padding>
<Insets bottom="3.0" left="-8.0" />
</padding>
</ComboBox>
</children>
<VBox.margin>
<Insets bottom="10.0" left="20.0" right="20.0" top="10.0" />
</VBox.margin>
</HBox>
<HBox prefHeight="38.0" prefWidth="300.0">
<children>
<JFXButton onAction="#Login" prefHeight="38.0" prefWidth="109.0" stylesheets="@../../resources/css/Consolidated.css" text="Login">
<styleClass>
<String fx:value="btns" />
<String fx:value="robotReg" />
</styleClass>
<HBox.margin>
<Insets left="27.25" right="27.25" />
</HBox.margin>
</JFXButton>
<JFXButton onAction="#cancel" prefHeight="38.0" prefWidth="109.0" stylesheets="@../../resources/css/Consolidated.css" text="Cancel">
<styleClass>
<String fx:value="btns" />
<String fx:value="robotReg" />
</styleClass>
<HBox.margin>
<Insets left="27.25" right="27.25" />
</HBox.margin>
</JFXButton>
</children>
<VBox.margin>
<Insets top="30.0" />
</VBox.margin>
</HBox>
</children>
</VBox>
</children>
</AnchorPane>
答案 0 :(得分:1)
您将Label
的位置和大小设置为Pane
中的绝对大小,这意味着Label
保持其左上角坐标,但会根据其首选大小调整大小。< / p>
除了这样做之外,您应该使用父布局来调整其可调整大小的子级,例如: VBox
。
用以下内容替换Pane
:
<VBox alignment="TOP_CENTER" prefHeight="148.0" prefWidth="300.0" styleClass="loginPaneBackground" AnchorPane.bottomAnchor="291.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" spacing="12.0">
<children>
<ImageView fitHeight="70.0" fitWidth="70.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../resources/imgs/login_img.png" />
</image>
</ImageView>
<Label fx:id="isConnected" alignment="CENTER" maxWidth="Infinity" text="Login" textFill="WHITE">
<font>
<Font name="Roboto Regular" size="24.0" />
</font>
<styleClass>
<String fx:value="robotBold" />
<String fx:value="loginLabel" />
</styleClass>
</Label>
</children>
<padding>
<Insets bottom="24.0" top="14.0" />
</padding>
</VBox>