不同屏幕上JavaFX的不同大小

不同屏幕上JavaFX的不同大小,java,javafx,size,resolution,borderpane,Java,Javafx,Size,Resolution,Borderpane,我一直在努力使我的JavaFX应用程序在不同的设备上大小合适。我认为这是因为屏幕上的分辨率不同。我在Macbook Pro Retina 13上进行所有开发,它的分辨率为2560x1600,而在运行1920x1080的Windows桌面上,窗口看起来不同。我将用两张图片来说明 2560x1600 1920x1080 我的第一个猜测是,这是因为边框窗格将在1920x1080上增加大小。所以我试着用下面的代码修复这个大小 <BorderPane maxHeight="304.0&

我一直在努力使我的JavaFX应用程序在不同的设备上大小合适。我认为这是因为屏幕上的分辨率不同。我在Macbook Pro Retina 13上进行所有开发,它的分辨率为
2560x1600
,而在运行
1920x1080
的Windows桌面上,窗口看起来不同。我将用两张图片来说明

2560x1600

1920x1080

我的第一个猜测是,这是因为边框窗格将在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">

正如James_D在评论中指出的,我的代码中有冗余节点。我使用了场景生成器,默认情况下他们添加了不需要的锚窗格,所以我假设它是准确的。然而,事实并非如此。

你能明确地说出问题所在吗?是“选择配置文件”组合和窗口边缘之间的右侧空间(类似于“升级”按钮)?您可以发布布局的FXML吗?问题是TableView的右侧空间。我希望它能像在更高分辨率的屏幕上一样到达右边缘。我也添加了fxml文件。您在该布局中似乎有很多冗余节点。例如,锚定窗格仅包含边框窗格;为什么不让边框窗格成为根元素呢?同样,表是锚窗格的唯一子级;同样,您可以完全删除锚定窗格。我不知道为什么会有滚动窗格;表管理自己的滚动。在
HBox
上使用
填充
间距
,而不是空窗格。首先,我会简化布局,并可能删除显式大小设置(例如,表上的
prefWidth
prefHeight
)。我使用了场景生成器,他们添加了这些锚窗格,所以我认为这是一种方法。
<?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 &amp; 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>