I need a GridPane
with two columns – fixed column with Label
(column width must be equal to label width) and a growing column with stretchable ComboBox
. This is my code:
public class JavaFxTest7 extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
var label = new Label("Label Is Here");
var comboBox = new ComboBox<String>();
HBox.setHgrow(comboBox, Priority.ALWAYS);
var comboBoxWrapper = new HBox(comboBox);
comboBox.maxWidthProperty().bind(comboBoxWrapper.widthProperty());
ColumnConstraints column0 = new ColumnConstraints();
column0.setHgrow(Priority.NEVER);
ColumnConstraints column1 = new ColumnConstraints();
column1.setHgrow(Priority.ALWAYS);
var gridPane = new GridPane();
gridPane.getColumnConstraints().addAll(column0, column1);
gridPane.add(label, 0, 0);
gridPane.add(comboBoxWrapper, 1, 0);
//comboBox.setItems(FXCollections.observableArrayList(List.of ("A", "B"))); //LINE X
var scene = new Scene(gridPane, 450, 200);
stage.setScene(scene);
stage.show();
}
}
And this is the result:
As you see everything is OK and this is what I need. However, if I add items to ComboBox
(uncomment Line X
) then column with label is not fixed any more:
Could anyone say if it is a bug and how it can be fixed?