Why does the running JavaFX application scene size differ from the scenebuilder preview

后端 未结 1 606
天涯浪人
天涯浪人 2020-12-22 11:19

I\'ve got a problem with the view of the application gui in Scene Builder in comparison to running one.

The app UI in the scene builder preview looks like this:

相关标签:
1条回答
  • 2020-12-22 11:46

    In SceneBuilder, set the Max Height and Max Width to USE_PREF_SIZE. Likewise, you can also set the min values.

    Also, for a scene such as this, BorderPane might be overkill. You could easily use a StackPane with an VBox, or even a GridPane.

    !! Edit !!

    Try this:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <?import javafx.geometry.*?>
    <?import javafx.scene.control.*?>
    <?import java.lang.*?>
    <?import javafx.scene.layout.*?>
    <?import javafx.scene.layout.BorderPane?>
    
    <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="180.0" prefWidth="260.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
       <children>
          <VBox layoutX="45.0" layoutY="37.0" spacing="12.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
             <children>
                <TextField fx:id="txtUserName" />
                <TextField fx:id="txtPassword" />
                <HBox>
                   <children>
                      <Pane HBox.hgrow="ALWAYS" />
                      <Button fx:id="btnOk" mnemonicParsing="false" text="Button" />
                   </children>
                </HBox>
             </children>
             <padding>
                <Insets bottom="18.0" left="18.0" right="18.0" top="18.0" />
             </padding>
          </VBox>
       </children>
    </AnchorPane>
    
    0 讨论(0)
提交回复
热议问题