我在JavaFX中遇到问题。运行程序时,文本比SceneBuilder中的文本大。
运行程序: JavaFX Window SceneBuilder: Window in SceneBuilder
这是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上可以正常工作。
答案 0 :(得分:1)
在不同的JavaFX版本/操作系统之间,字体大小/精确控件大小可能有所不同。您不应该在这里使用绝对位置。我建议使用一种布局,根据其大小选择子项的位置。合适的布局应为GridPane
(如果要确保单元数保持不变,而与字体大小窗口大小等无关,并且ComboBox
应该水平对齐)或FlowPane
(如果需要)放置一堆类似于文本的ComboBox
,而不关心水平对齐方式或每行ComboBox
的确切数量)。
...
<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>
...