JavaFX缩放元素到屏幕分辨率

时间:2015-09-08 08:45:06

标签: java user-interface javafx scenebuilder

我使用SceneBuilder在JavaFX中创建了一个GUI,它在窗口模式下完美运行。它看起来像这样;

enter image description here

我想要做的是运行程序最大化(不是全屏),理想情况下根据阶段是否最大化来调整元素大小。这是GUI在程序最大化时的样子;

enter image description here

正如你可以看到一些古怪的理由,表格确实是"缩放"但是没有其他元素可以做到。我可以使用SceneBuilder中的一个设置,使元素流畅吗?

显示页面的FXML代码;

<?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>

编辑:我使用AnchorPane作为布局,为了清晰起见添加了FXML代码。

0 个答案:

没有答案