我一直在努力使我的JavaFX应用程序在不同设备上正常运行。我认为这是因为屏幕上的分辨率不同。我在我的Macbook Pro Retina 13上进行了所有开发,其分辨率为2560x1600
,而在运行1920x1080
的Windows桌面上,窗口看起来有所不同。我将用两张图片说明。
我的第一个猜测是因为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>
答案 0 :(得分:1)
就像James_D在评论中指出的那样,我的代码中有减少节点。我曾经使用过Scene Builder,他们默认添加了不需要的锚点窗格,所以我假设它是准确的。但是,它不是。