最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

resize - JavaFX stage size too small - Gridpane resizing - Stack Overflow

programmeradmin0浏览0评论

I created a JavaFX dialog in SceneBuilder. After playing probably an hour with the different layout attributes I can't find out how to open the stage in way, that all ui elements are properly displayed.

This is the way the stage opens:

You see, most columns are squeezed. The gray area below the Monday-Combobox, is actually another ComboBox, which is filled when initializing the UI with a number of ~20 character long Strings. But when opening, there is no default selection. Therefore, this ComboBox is blank.

This is how I would like the stage to open (after enlarging the stage with the mouse) .

I guess the issue is related to a missing resize of the stage after filling the ComboBox, triggering a resize of the ComboBox at the cost of the other columns. But this is just a guess. I wonder which setting is missing or wrong.

I am not after a solution, which is based on brut force setting the width programatically to a certain value or where I have to go through the interface and calculate the width of the stage based on the prefered width of the children. I am hopeing for a set of layout settings that does the trick.

This is the fxml code:

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

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>

<GridPane fx:id="parentGridPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" stylesheets="@application.css" xmlns="; xmlns:fx="; fx:controller="de.levin.ctrl.TrainingPlanEditorCtrl">
   <children>
      <ComboBox fx:id="startHourComboBox" GridPane.columnIndex="1" GridPane.rowIndex="1">
         <GridPane.margin>
            <Insets top="6.0" />
         </GridPane.margin>
      </ComboBox>
      <ComboBox fx:id="startMinutesComboBox" GridPane.columnIndex="3" GridPane.rowIndex="1">
         <GridPane.margin>
            <Insets right="6.0" top="6.0" />
         </GridPane.margin>
      </ComboBox>
      <ComboBox fx:id="endHourComboBox" GridPane.columnIndex="1" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets bottom="12.0" top="6.0" />
         </GridPane.margin>
      </ComboBox>
      <ComboBox fx:id="endMinutesComboBox" GridPane.columnIndex="3" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets bottom="12.0" right="6.0" top="6.0" />
         </GridPane.margin>
      </ComboBox>
      <Label text=":" GridPane.columnIndex="2" GridPane.rowIndex="1">
         <GridPane.margin>
            <Insets left="3.0" right="3.0" />
         </GridPane.margin>
      </Label>
      <Label text=":" GridPane.columnIndex="2" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets left="3.0" right="3.0" />
         </GridPane.margin>
      </Label>
      <Label text="Start" GridPane.rowIndex="1">
         <GridPane.margin>
            <Insets left="12.0" right="6.0" />
         </GridPane.margin>
      </Label>
      <Label text="End" GridPane.rowIndex="2">
         <GridPane.margin>
            <Insets left="12.0" right="6.0" />
         </GridPane.margin>
      </Label>
      <Button fx:id="addDayButton" mnemonicParsing="false" onAction="#addDay" text="+" GridPane.columnIndex="5">
         <GridPane.margin>
            <Insets right="12.0" top="12.0" />
         </GridPane.margin>
      </Button>
      <Button fx:id="addIntervallButton" mnemonicParsing="false" onAction="#addIntervall" text="+" GridPane.columnIndex="1" GridPane.rowIndex="3">
         <GridPane.margin>
            <Insets bottom="12.0" top="12.0" />
         </GridPane.margin>
      </Button>
      <Separator prefWidth="200.0" GridPane.columnSpan="2147483647" GridPane.rowIndex="4">
         <GridPane.margin>
            <Insets bottom="6.0" top="6.0" />
         </GridPane.margin>
      </Separator>
      <Button fx:id="okButton" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#ok" text="OK" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.rowIndex="5">
         <GridPane.margin>
            <Insets bottom="24.0" top="6.0" />
         </GridPane.margin>
      </Button>
      <Button fx:id="cancelButton" mnemonicParsing="false" onAction="#cancel" text="Cancel" GridPane.columnIndex="4" GridPane.rowIndex="5">
         <GridPane.margin>
            <Insets bottom="24.0" top="6.0" />
         </GridPane.margin>
      </Button>
      <ScrollPane fx:id="daysScrollPane" GridPane.columnIndex="4" GridPane.hgrow="ALWAYS" GridPane.rowSpan="3" GridPane.vgrow="ALWAYS">
         <content>
            <GridPane fx:id="gridPane" maxWidth="1.7976931348623157E308">
              <columnConstraints>
                <ColumnConstraints />
              </columnConstraints>
              <rowConstraints>
                <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
                <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
                <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
              </rowConstraints>
               <children>
                  <ComboBox fx:id="dayComboBox">
                     <GridPane.margin>
                        <Insets bottom="6.0" right="12.0" />
                     </GridPane.margin>
                  </ComboBox>
                  <ComboBox fx:id="sessionComboBox" maxHeight="1.7976931348623157E308" GridPane.rowIndex="1" GridPane.rowSpan="2">
                     <GridPane.margin>
                        <Insets right="12.0" />
                     </GridPane.margin>
                  </ComboBox>
               </children>
            </GridPane>
         </content>
         <GridPane.margin>
            <Insets right="12.0" top="12.0" />
         </GridPane.margin>
      </ScrollPane>
   </children>
   <columnConstraints>
      <ColumnConstraints />
      <ColumnConstraints />
      <ColumnConstraints />
      <ColumnConstraints />
      <ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="10.0" />
      <ColumnConstraints />
   </columnConstraints>
   <rowConstraints>
      <RowConstraints minHeight="10.0" />
      <RowConstraints />
      <RowConstraints minHeight="10.0" />
      <RowConstraints minHeight="10.0" />
      <RowConstraints minHeight="10.0" vgrow="NEVER" />
      <RowConstraints minHeight="10.0" vgrow="NEVER" />
   </rowConstraints>
</GridPane>
发布评论

评论列表(0)

  1. 暂无评论