JavaFX自动缩放

时间:2015-07-16 14:17:36

标签: java javafx scaling scenebuilder

我希望,当我增加窗口时,元素也会变大。

见这里:See here

我正在使用JavaFX Scenebuilder 2.0:enter image description here

Start.fxml :     

<?import javafx.scene.effect.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>

<AnchorPane cacheHint="SCALE" focusTraversable="true" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
   <children>
      <Button fx:id="delteRowBtn" layoutX="25.0" layoutY="272.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#delRowAction" prefHeight="30.0" prefWidth="51.0" text="Zeile" />
      <Button fx:id="addColumnBtn" layoutX="193.0" layoutY="272.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#addColumnAction" prefHeight="30.0" prefWidth="51.0" text="Spalte" />
      <Button fx:id="moveBtn" layoutX="258.0" layoutY="272.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="30.0" prefWidth="90.0" text="MOVE" />
      <Button fx:id="linkBtn" layoutX="363.0" layoutY="272.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="30.0" prefWidth="90.0" text="LINK" />
      <Button fx:id="splitBtn" layoutX="468.0" layoutY="272.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="30.0" prefWidth="90.0" text="SPLIT" />
      <Button fx:id="tcodeBtn" layoutX="574.0" layoutY="272.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="30.0" prefWidth="90.0" text="TRANSCODE" />
      <Button fx:id="cnvrtBtn" layoutX="679.0" layoutY="272.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="30.0" prefWidth="90.0" text="CONVERT" />
      <Button fx:id="saveBtn" layoutX="684.0" layoutY="551.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#saveAction" prefHeight="30.0" prefWidth="90.0" text="SAVE" />
      <TableView fx:id="sourceTable" editable="true" layoutX="17.0" layoutY="40.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="190.0" prefWidth="766.0" />
      <TableView fx:id="finalTable" layoutX="17.0" layoutY="348.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="190.0" prefWidth="766.0" />
      <Button fx:id="openBtn" layoutX="572.0" layoutY="551.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#openAction" prefHeight="30.0" prefWidth="90.0" text="OPEN" />
      <TextField fx:id="srcInput" editable="false" layoutX="69.0" layoutY="551.0" prefHeight="30.0" prefWidth="495.0" />
      <TextField editable="false" layoutX="17.0" layoutY="11.0" text="Source File" />
      <TextField editable="false" layoutX="17.0" layoutY="319.0" text="Converted File" />
      <Button fx:id="delteColumnBtn" layoutX="77.0" layoutY="272.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#delColumnAction" prefHeight="30.0" prefWidth="51.0" text="Spalte" />
      <Button fx:id="addRowBtn" layoutX="141.0" layoutY="272.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#addRowAction" prefHeight="30.0" prefWidth="51.0" text="Zeile" />
      <Label contentDisplay="CENTER" layoutX="140.0" layoutY="248.0" prefHeight="25.0" prefWidth="104.0" text="    HINZUFÜGEN" textAlignment="CENTER" />
      <Label contentDisplay="CENTER" layoutX="24.0" layoutY="248.0" prefHeight="25.0" prefWidth="104.0" text="      LÖSCHEN" textAlignment="CENTER" />
   </children>
</AnchorPane>

1 个答案:

答案 0 :(得分:1)

你需要锚定所有四个方面。当屏幕放大时,这将导致它们伸展。如果你只想加宽而不是更高,锚定到左,右和顶部,但不是底部。您可以更轻松地使用图形场景构建器测试界面,以设置类似的小细节,而无需进行试验和错误编译。如果这样做,您仍然可以手动编辑fxml和css文件。这是链接:http://www.oracle.com/technetwork/java/javase/downloads/sb2download-2177776.html

我发现在使用JavaFX

时与手动编码结合使用非常有用