标签:java javafx javafx-2 javafx-8
原始尺寸截图
全屏截图
当我调整大小时,我如何很好地安排组件.
即时通讯使用FXML进行GUI
FXML代码
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="style.LoginController">
<children>
<Button fx:id="login" layoutX="250.0" layoutY="242.0" mnemonicParsing="false" onAction="#login" prefHeight="32.0" prefWidth="101.0" text="Login" />
<ImageView fx:id="img2" fitHeight="32.0" fitWidth="32.0" layoutX="109.0" layoutY="184.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../../../../Downloads/Drawing%20(23).png" />
</image>
</ImageView>
<Label fx:id="title" alignment="CENTER" focusTraversable="false" layoutX="166.0" layoutY="48.0" opacity="0.83" prefHeight="42.0" prefWidth="269.0" styleClass="title" text="Label" textAlignment="CENTER" textOverrun="CENTER_ELLIPSIS">
<font>
<Font name="Arial Narrow" size="36.0" />
</font>
</Label>
<TextField fx:id="txtusername" layoutX="159.0" layoutY="126.0" prefHeight="32.0" prefWidth="283.0" promptText="Username" styleClass="fields" />
<PasswordField fx:id="txtpassword" layoutX="159.0" layoutY="183.0" prefHeight="32.0" prefWidth="283.0" promptText="Password" styleClass="fields" />
<ImageView fx:id="img1" fitHeight="32.0" fitWidth="32.0" layoutX="109.0" layoutY="126.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../../../../Downloads/Drawing%20(22).png" />
</image>
</ImageView>
<ProgressIndicator fx:id="progress" layoutX="197.0" layoutY="120.0" minHeight="0.0" minWidth="0.0" prefHeight="128.0" prefWidth="188.0" progress="0.0" styleClass="progressind" />
</children>
</AnchorPane>
解决方法:
问题是因为您使用AnchorPane作为根窗格.虽然,你可以将AnchorPane用于这样的场景,但我个人不喜欢它,因为你需要做很多事情才能做到正确.有更简单的方法,这就是我要告诉你的.
来自Javadocs:
AnchorPane allows the edges of child nodes to be anchored to an offset from the anchor pane’s edges.
解
使用不同的布局.可以是GridPane或VBox.这些布局具有子alignment而不是锚,这允许儿童与特定位置对齐.
要重新调整孩子的大小,可以在其上设置HGrow/VGrow属性.
例
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" spacing="20.0" style="-fx-background-color: DARKCYAN;" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label text="Easy Doctor" />
<TextField promptText="Username" />
<TextField promptText="Password" />
</children>
<padding>
<Insets bottom="50.0" left="50.0" right="50.0" top="50.0" />
</padding>
</VBox>
这是一个关于它看起来如何的小gif:
标签:java,javafx,javafx-2,javafx-8 来源: https://codeday.me/bug/20190611/1221418.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。