I have an editable ComboBox
and I want to add to items the values an user enters. However, when items list is changed then the text in ComboBox
editor also changes.
This is my code:
<code>public class JavaFxTest7 extends Application {
@Override
public void start(Stage stage) {
var list = List.of("A", "B", "C");
var comboBox = new ComboBox<String>();
comboBox.setEditable(true);
comboBox.setItems(FXCollections.observableArrayList(list));
var button = new Button("Push Me");
button.setOnAction(e -> {
comboBox.getItems().add(0, comboBox.getValue());
});
Scene scene = new Scene(new VBox(comboBox, button), 400, 200);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
</code>
<code>public class JavaFxTest7 extends Application {
@Override
public void start(Stage stage) {
var list = List.of("A", "B", "C");
var comboBox = new ComboBox<String>();
comboBox.setEditable(true);
comboBox.setItems(FXCollections.observableArrayList(list));
var button = new Button("Push Me");
button.setOnAction(e -> {
comboBox.getItems().add(0, comboBox.getValue());
});
Scene scene = new Scene(new VBox(comboBox, button), 400, 200);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
</code>
public class JavaFxTest7 extends Application {
@Override
public void start(Stage stage) {
var list = List.of("A", "B", "C");
var comboBox = new ComboBox<String>();
comboBox.setEditable(true);
comboBox.setItems(FXCollections.observableArrayList(list));
var button = new Button("Push Me");
button.setOnAction(e -> {
comboBox.getItems().add(0, comboBox.getValue());
});
Scene scene = new Scene(new VBox(comboBox, button), 400, 200);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
and this is a result:
Could anyone say if this is a bug or I am doing something wrong?