簡體   English   中英

JavaFX-縮放窗格的內部元素

[英]JavaFX- scaling the inner elements of a Pane

當我增加窗口時,內部元素將保持相同的大小。

我希望當我增加窗口時,元素也變大/縮放

Main.fxml:

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

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane cacheHint="SCALE_AND_ROTATE" focusTraversable="true" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
   <children>
     <TableView fx:id="finalTable" layoutX="27.0" layoutY="358.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="190.0" prefWidth="766.0" />
     <Label layoutX="27.0" layoutY="21.0" prefHeight="25.0" prefWidth="149.0" text="   Quell-Datei" />
     <TableView fx:id="sourceTable" editable="true" layoutX="27.0" layoutY="50.0" maxHeight="900.0" maxWidth="900.0" minHeight="-Infinity" minWidth="-Infinity" prefHeight="190.0" prefWidth="766.0" />
     <Label layoutX="27.0" layoutY="329.0" prefHeight="25.0" prefWidth="149.0" text="   Konvertierte-Datei" />
     <Button fx:id="linkBtn" layoutX="313.0" layoutY="282.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#linkAction" prefHeight="30.0" prefWidth="90.0" text="Verbinden" />
     <Button fx:id="splitBtn" layoutX="437.0" layoutY="282.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#splitAction" prefHeight="30.0" prefWidth="90.0" text="Trennen" />
     </children>
</AnchorPane>

我正在使用SceneBuilder 2.0,而且我還嘗試過“錨定”按鈕
(請參見此處: http : //i.imgur.com/GZyL5xC.png
...但是縮放比例是完全錯誤的(請參閱此處: http : //i.imgur.com/hmMi1p3.png

我在整個互聯網上搜索了答案,但沒有找到任何可以幫助的答案。

好吧,您的布局通常是VBox布局。 如果您的Windows尺寸不是固定的,這將是一個很好的解決方案,因為您的Button保持相同的高度並位於窗口的中心。 調整窗口大小時,TableViews會增大和縮小。 像你要的那樣。

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

<?import javafx.geometry.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>


<VBox xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
   <children>
     <Label prefHeight="25.0" prefWidth="149.0" text="   Quell-Datei" VBox.vgrow="NEVER" />
     <TableView fx:id="sourceTable" editable="true" prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS" />
      <Label />
      <HBox alignment="CENTER" prefHeight="61.0" prefWidth="766.0" spacing="20.0" VBox.vgrow="NEVER">
         <children>
           <Button fx:id="linkBtn" maxHeight="-Infinity" maxWidth="-Infinity" mnemonicParsing="false" onAction="#linkAction" prefHeight="30.0" prefWidth="90.0" text="Verbinden" HBox.hgrow="NEVER" />
           <Button fx:id="splitBtn" maxHeight="-Infinity" maxWidth="-Infinity" mnemonicParsing="false" onAction="#splitAction" prefHeight="30.0" prefWidth="90.0" text="Trennen" HBox.hgrow="NEVER" />
         </children>
      </HBox>
     <Label prefHeight="25.0" prefWidth="149.0" text="   Konvertierte-Datei" VBox.vgrow="NEVER" />
     <TableView fx:id="finalTable" prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS" />
   </children>
   <padding>
      <Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
   </padding>
</VBox>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM