简体   繁体   English

JavaFX-缩放窗格的内部元素

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

When I increase the window, the inner elements stay at the same size. 当我增加窗口时,内部元素将保持相同的大小。

I want that when I increase the window, that the elements also get larger/scale 我希望当我增加窗口时,元素也变大/缩放

Main.fxml: 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>

Im working with SceneBuilder 2.0, and I have also tried to "anchor" a button 我正在使用SceneBuilder 2.0,而且我还尝试过“锚定”按钮
(see here: http://i.imgur.com/GZyL5xC.png ) (请参见此处: http : //i.imgur.com/GZyL5xC.png
...but the scaling is completely wrong (see here: http://i.imgur.com/hmMi1p3.png ) ...但是缩放比例是完全错误的(请参阅此处: http : //i.imgur.com/hmMi1p3.png

I searched the whole internet for an answer, but I found nothing that could help. 我在整个互联网上搜索了答案,但没有找到任何可以帮助的答案。

Well your layout is typically a VBox layout. 好吧,您的布局通常是VBox布局。 If your Windows isn't at a fixed size this will be a good solution, because your Buttons stay at the same height and in the center of your window. 如果您的Windows尺寸不是固定的,这将是一个很好的解决方案,因为您的Button保持相同的高度并位于窗口的中心。 The TableViews grow and shrink as you resize the window. 调整窗口大小时,TableViews会增大和缩小。 Like you want. 像你要的那样。

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