I have two Button
s and two ComboBox
es . The width of buttons is unknown as the text depends on the language. ComboBox
es must stretch maximum, but they must always have same width. I mean that comboBox1.getWidth()
must be equal to comboBox2.getWidth()
.
This is my code:
public class JavaFxTest7 extends Application {
@Override
public void start(Stage stage) {
var button1 = new Button("Text with unknown length");
var comboBox1 = new ComboBox<String>();
comboBox1.setEditable(true);
comboBox1.setMaxWidth(Double.MAX_VALUE);
var toolBar1 = new ToolBar(comboBox1, button1);
HBox.setHgrow(comboBox1, Priority.ALWAYS);
var button2 = new Button("Another text with unknown length");
var comboBox2 = new ComboBox<String>();
comboBox2.setEditable(true);
comboBox2.setMaxWidth(Double.MAX_VALUE);
HBox.setHgrow(comboBox2, Priority.ALWAYS);
var toolBar2 = new ToolBar(comboBox2, button2);
Scene scene = new Scene(new VBox(toolBar1, toolBar2), 800, 200);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
Could anyone say how to do it?