JavaFX Scale Elements to Screen Resolution

故事扮演 提交于 2020-01-06 01:46:15

问题


I've created a GUI in JavaFX using SceneBuilder that works perfectly in windowed mode. It looks like this;

What I would like to do is run the program maximised (not full screen) and ideally have the elements resize according to whether the stage is maximised or not. This is what the GUI looks like when the program is maximised;

As you can see for some bizzare reason the table does "scale" however none of the other elements do. Is there a setting in SceneBuilder I can use that makes the elements fluid?

FXML code for displayed page;

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.GridPane?>

<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" onKeyPressed="#handleRefresh" prefHeight="634.0" prefWidth="602.0" stylesheets="@Style.css" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <TableView fx:id="tView" layoutX="20.0" layoutY="159.0" onKeyPressed="#handleRefresh" prefHeight="389.0" prefWidth="601.0" AnchorPane.bottomAnchor="86.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="31.0" AnchorPane.topAnchor="159.0">
        <columns>
          <TableColumn fx:id="caseNumCol" prefWidth="75.0" text="CaseNO" />
          <TableColumn fx:id="caseNotesCol" prefWidth="75.0" text="Case Notes" />
            <TableColumn fx:id="dateCreatedCol" prefWidth="75.0" text="Date Created" />
            <TableColumn fx:id="deadlineDateCol" prefWidth="75.0" text="Deadline" />
            <TableColumn fx:id="priorityCol" prefWidth="75.0" text="Priority" />
            <TableColumn fx:id="completedCol" prefWidth="75.0" text="Completed" />
        </columns>
         <columnResizePolicy>
            <TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
         </columnResizePolicy>
      </TableView>
      <Button layoutX="66.0" layoutY="559.0" mnemonicParsing="false" onAction="#handleAddButtonAction" prefHeight="25.0" prefWidth="79.0" text="Add Job" />
      <Button layoutX="322.0" layoutY="559.0" mnemonicParsing="false" onAction="#handleDeleteButtonAction" prefHeight="25.0" prefWidth="79.0" text="Delete Job" />
      <Label layoutX="14.0" layoutY="6.0" prefHeight="58.0" prefWidth="245.0" text="SDC Job Manager">
         <font>
            <Font name="System Bold" size="28.0" />
         </font>
      </Label>
      <Line endX="500" layoutX="101.0" layoutY="72.0" startX="-100.0" />
      <Label fx:id="adamLabel" alignment="CENTER" layoutX="153.0" layoutY="98.0" prefHeight="30.0" prefWidth="295.0" text="Adam's Jobs" visible="false">
         <font>
            <Font size="24.0" />
         </font>
      </Label>
      <Label fx:id="kitLabel" alignment="CENTER" layoutX="153.0" layoutY="98.0" prefHeight="30.0" prefWidth="295.0" text="Kit's Jobs" visible="false">
         <font>
            <Font size="24.0" />
         </font>
      </Label>
      <Label fx:id="userLabel" layoutX="428.0" layoutY="24.0" prefHeight="20.0" prefWidth="162.0">
         <font>
            <Font name="System Bold" size="14.0" />
         </font>
      </Label>
      <Button layoutX="197.0" layoutY="559.0" mnemonicParsing="false" onAction="#handleUpdateButtonAction" prefHeight="25.0" prefWidth="79.0" text="Update Job" />
      <Label layoutX="20.0" layoutY="90.0" prefHeight="17.0" prefWidth="107.0" text="Press F5 To Refresh" />
      <Button layoutX="447.0" layoutY="559.0" mnemonicParsing="false" onAction="#handleBackButtonAction" prefHeight="25.0" prefWidth="79.0" text="Back" AnchorPane.bottomAnchor="50.0" AnchorPane.leftAnchor="447.0" AnchorPane.rightAnchor="76.0" AnchorPane.topAnchor="559.0" />
   </children>
</AnchorPane>

EDIT: I am using an AnchorPane as a layout, added FXML code for clarity.

来源:https://stackoverflow.com/questions/32453173/javafx-scale-elements-to-screen-resolution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!