我一直在努力使我的 JavaFX 应用程序大小在不同的设备上正确。我认为这是因为屏幕上的分辨率不同。我正在我的 Macbook Pro Retina 13 上进行所有开发,它的分辨率为2560x1600
,而我的 Windows 桌面上运行的窗口看起来不同1920x1080
。我用两张图来说明。
2560x1600
1920x1080
我的第一个猜测是,这是因为 BorderPane 的尺寸会在 1920x1080 上增加。所以我尝试使用以下代码修复大小。
<BorderPane maxHeight="304.0" maxWidth="414.0" minHeight="304.0"
minWidth="414.0" prefHeight="304.0" prefWidth="414.0"
xmlns="http://javafx.com/javafx/8.0.40"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="controller.GUIController">
不过,这并没有改变任何东西。任何想法如何解决这个问题?
编辑:我希望它2560x1600
基本上看起来像。
编辑: FXML 文件如下所示。
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controller.GUIController">
<children>
<BorderPane>
<center>
<ScrollPane BorderPane.alignment="CENTER">
<content>
<AnchorPane>
<children>
<TableView fx:id="itemList" prefHeight="214.0" prefWidth="412.0">
<columns>
<TableColumn fx:id="nameColumn" editable="false" resizable="false" text="Name" />
<TableColumn fx:id="powerColumn" editable="false" resizable="false" text="Power" />
<TableColumn fx:id="typeColumn" editable="false" resizable="false" text="Type" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
</children>
</AnchorPane>
</content>
</ScrollPane>
</center>
<bottom>
<HBox alignment="CENTER_LEFT" BorderPane.alignment="CENTER">
<children>
<HBox prefHeight="40.0" prefWidth="6.0" />
<Label prefHeight="17.0" prefWidth="37.0" text="Item: ">
<font>
<Font name="System Regular" size="12.0" />
</font>
</Label>
<ComboBox fx:id="newCBox" onAction="#addItemClicked" prefHeight="27.0" prefWidth="112.0" promptText="New" />
<HBox prefHeight="40.0" prefWidth="40.0" />
<Button mnemonicParsing="false" onAction="#importClicked" prefHeight="27.0" prefWidth="64.0" text="Import" />
<HBox prefHeight="40.0" prefWidth="5.0" />
<Button mnemonicParsing="false" onAction="#removeClicked" prefHeight="27.0" prefWidth="68.0" text="Remove" />
<HBox prefHeight="40.0" prefWidth="5.0" />
<Button mnemonicParsing="false" onAction="#upgradeClicked" prefHeight="27.0" prefWidth="72.0" text="Upgrade" />
</children>
</HBox>
</bottom>
<top>
<VBox alignment="CENTER_RIGHT" prefHeight="58.0" prefWidth="414.0" BorderPane.alignment="CENTER">
<children>
<MenuBar>
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem fx:id="savedMenu" mnemonicParsing="false" onAction="#saveClicked" text="Save" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem fx:id="openMenu" mnemonicParsing="false" onAction="#openClicked" text="Open" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Item">
<items>
<MenuItem fx:id="editItemMenu" mnemonicParsing="false" onAction="#editItemClicked" text="Edit" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem fx:id="importMenu" mnemonicParsing="false" onAction="#importClicked" text="Import" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem fx:id="removeMenu" mnemonicParsing="false" onAction="#removeClicked" text="Remove" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem fx:id="upgradeMenu" mnemonicParsing="false" onAction="#upgradeClicked" text="Upgrade" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Profile">
<items>
<MenuItem id="editValues" fx:id="editValues" mnemonicParsing="false" onAction="#editValuesClicked" text="Edit & New" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" onAction="#shareProfileClicked" text="Share Profile" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" onAction="#loadProfileClicked" text="Load Profile" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" onAction="#removeProfileClicked" text="Remove" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" onAction="#aboutClicked" text="About" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" onAction="#newsClicked" text="News" />
</items>
</Menu>
</menus>
</MenuBar>
<HBox alignment="CENTER_LEFT">
<children>
<HBox prefHeight="31.0" prefWidth="5.0" />
<Label text="Display: " />
<ComboBox fx:id="displayCBox" onAction="#displayChanged" prefHeight="27.0" prefWidth="149.0" promptText="Display type" />
<HBox prefHeight="31.0" prefWidth="59.0" />
<ComboBox fx:id="profileCBox" onAction="#profileChanged" prefHeight="27.0" prefWidth="143.0" promptText="Choose Profile" />
</children>
</HBox>
</children>
</VBox>
</top>
</BorderPane>
</children>
</AnchorPane>