admin管理员组文章数量:1333451
I am trying to add programatically a ComboBox to an existing GridPane, called daysGridPane. This ComboBox is supposed to span two rows. The complete setup is a little bit more complex, as the daysGridPane is embedded in another Gridpane, called parentGridPane. Reason is that I need to be able to scroll the content of the daysGridPane, while the rest of the UI remains visible. The trouble is that the added ComboBox does not span the two rows. It only covers the upper cell. When the stage is shown, the first ComboBox below the "Monday"-ComboBox, originates from the fxml definition of the UI in SceneBuilder. I created a second ComboBox in SceneBuilder, spanning two rows, and copied all the setting equivalents to the code. Doesn't work.
On the snapshot you can see the grid-lines. I find it noteworthy, that the added rows are smaller, compared to the rows of the parentGridPane, but I am not sure whether this has to do with the root cause.
Here is the underlying fxml file:
<?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="daysGridPane" 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>
Here is the code, that is supposed to add the row-spanning ComboBox:
@FXML
protected void addIntervall(ActionEvent event) {
// Find the index for the new column
int newRowIndex = parentGridPane.getRowConstraints().size() -3; // add-intervall, ok, cancel button rows
...
// extend session daysGridPane
GridPane.setRowSpan(daysScrollPane, GridPane.getRowSpan(daysScrollPane) + 2);
daysGridPane.setGridLinesVisible(true);
RowConstraints rowC1 = new RowConstraints(); // we need two new rows that are spaned by the new ComboBox
RowConstraints rowC2 = new RowConstraints();
rowC1.setVgrow(Priority.ALWAYS);
rowC1.setMaxHeight(Double.MAX_VALUE);
rowC1.setFillHeight(true);
rowC2.setVgrow(Priority.ALWAYS);
rowC2.setMaxHeight(Double.MAX_VALUE);
rowC2.setFillHeight(true);
daysGridPane.getRowConstraints().add(newRowIndex, rowC1 );
daysGridPane.getRowConstraints().add(newRowIndex, rowC2);
ComboBox<Session> newSessionCB = new ComboBox<Session>();
daysGridPane.add(newSessionCB, 0, newRowIndex);
GridPane.setRowSpan(newSessionCB, 2);
newSessionCB.setMaxHeight(Double.MAX_VALUE);
GridPane.setVgrow(newSessionCB, Priority.ALWAYS);
newSessionCB.setItems(persistance.loadSessions(null));
}
What am I missing?
本文标签: JavaFX ComboBox rowSpan in GridPane not working programaticallyStack Overflow
版权声明:本文标题:JavaFX ComboBox rowSpan in GridPane not working programatically - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742353841a2459022.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论