javafx - JavaFX - 编译时的文本比 SceneBuilder 中的大
问题描述
我在 JavaFX 中遇到问题。运行程序时的文本比 SceneBuilder 中的要大。
运行程序: JavaFX Window SceneBuilder: SceneBuilder中的Window
这是 fxml 文件:
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="200.0" minWidth="450.0" prefHeight="200.0"prefWidth="450.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
<children>
<GridPane layoutX="24.0" layoutY="14.0" prefWidth="406.0" AnchorPane.bottomAnchor="60.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="5.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="100.0" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="180.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="85.0" minWidth="10.0" prefWidth="85.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="40.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Rozszerzenie" />
<Label text="Główny katalog" GridPane.rowIndex="1" />
<Label text="Katolog docelowy" GridPane.rowIndex="2" />
<Button mnemonicParsing="false" onAction="#chooseMainDirectory" text="Przeszukaj" GridPane.columnIndex="2" GridPane.rowIndex="1">
<GridPane.margin>
<Insets left="10.0" />
</GridPane.margin>
</Button>
<Button mnemonicParsing="false" onAction="#chooseTargetDirectory" text="Przeszukaj" GridPane.columnIndex="2" GridPane.rowIndex="2">
<GridPane.margin>
<Insets left="10.0" />
</GridPane.margin>
</Button>
<TextField fx:id="mainDirectory" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField fx:id="targetDirectory" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<AnchorPane fx:id="choiceDeck" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1">
<children>
<CheckBox layoutY="6.0" mnemonicParsing="false" text=".jpg" />
<CheckBox layoutX="48.0" layoutY="6.0" mnemonicParsing="false" text=".jpeg" />
<CheckBox layoutX="104.0" layoutY="6.0" mnemonicParsing="false" text=".gif" />
<CheckBox layoutX="150.0" layoutY="6.0" mnemonicParsing="false" text=".bmp" />
<CheckBox layoutY="30.0" mnemonicParsing="false" text=".png" />
<CheckBox layoutX="49.0" layoutY="30.0" mnemonicParsing="false" text=".tiff" />
</children>
</AnchorPane>
</children>
</GridPane>
<Button layoutX="368.0" layoutY="161.0" mnemonicParsing="false" onAction="#confirm" text="Zatwierdź" AnchorPane.bottomAnchor="14.0" AnchorPane.rightAnchor="14.0" />
<Button layoutX="14.0" layoutY="161.0" mnemonicParsing="false" onAction="#cancel" text="Anuluj" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="14.0" />
</children>
</AnchorPane>
请帮我解决这个问题。在另一台 PC 上它工作正常。
解决方案
不同的 JavaFX 版本/操作系统之间的字体大小/精确控件大小可能不同。你不应该在这里使用绝对位置。我建议使用一种布局,它会根据孩子的大小来选择孩子的位置。合适的布局将是GridPane
(如果您想确保单元格的数量保持不变,而不管字体大小窗口大小等。并且ComboBox
应该水平对齐)或FlowPane
(如果您想放置一堆ComboBox
类似于文本的 es 并且不关心水平对齐或ComboBox
每行 es的确切数量)。
...
<FlowPane fx:id="choiceDeck" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1">
<children>
<CheckBox mnemonicParsing="false" text=".jpg" />
<CheckBox mnemonicParsing="false" text=".jpeg" />
<CheckBox mnemonicParsing="false" text=".gif" />
<CheckBox mnemonicParsing="false" text=".bmp" />
<CheckBox mnemonicParsing="false" text=".png" />
<CheckBox mnemonicParsing="false" text=".tiff" />
</children>
</FlowPane>
...
...
<GridPane fx:id="choiceDeck" prefHeight="200.0" prefWidth="200.0" hgap="3" vgap="5" GridPane.columnIndex="1">
<children>
<CheckBox mnemonicParsing="false" text=".jpg" />
<CheckBox GridPane.columnIndex="1" mnemonicParsing="false" text=".jpeg" />
<CheckBox GridPane.columnIndex="2" mnemonicParsing="false" text=".gif" />
<CheckBox GridPane.columnIndex="3" mnemonicParsing="false" text=".bmp" />
<CheckBox GridPane.rowIndex="1" mnemonicParsing="false" text=".png" />
<CheckBox GridPane.rowIndex="1" GridPane.columnIndex="1" mnemonicParsing="false" text=".tiff" />
</children>
</GridPane>
...
推荐阅读
- laravel - 如何用他在 Laravel 中的关系返回一个模型?
- vim - 为什么 Vim 用红色突出显示我所有的 JSON 注释?
- reactjs - 如何检查上传的图像是否真的是图像
- python - 在 keras 上使用 evaluate_generator 的准确度得分不一致
- php - 在 PHP 中使用 CURL 查询 ElasticSearch 时遇到问题
- c++ - 对 vtbel 的未定义引用
- python - 使用 xpath 和 LXML 或 selenium 从 HTML 表中抓取数据
- ios - 如何从 UIViewController 中删除传递的闭包
- python - 为什么 Python 标准库中没有最大堆数据类型?
- r - 非零存在状态安装 openNLP