Reproduction:
1. Open the empty ComboBox. An empty (blank) entry pops up (I guess this is desired behavior)
2. Add two items to the ComboBox (Add Button).
3. Open the ComboBox and select the 2nd entry (or first)
4. Click Delete Button.
5. Open the ComboBox
=> The ComboBox displays the first added item AND a blank 2nd item, which feels buggy to me.
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import java.util.UUID;
public class TestApp3 extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(final Stage stage) throws Exception {
BorderPane borderPane = new BorderPane();
Scene scene = new Scene(new Group(), 450, 250);
ComboBox<String> myComboBox = new ComboBox<>();
Button add = new Button("Add");
add.setOnAction(event -> myComboBox.getItems().add(UUID.randomUUID().toString()));
Button delete = new Button("Delete");
delete.setOnAction(event -> myComboBox.getItems().remove(myComboBox.getSelectionModel().getSelectedItem()));
Group root = (Group) scene.getRoot();
borderPane.setTop(myComboBox);
borderPane.setCenter(add);
borderPane.setBottom(delete);
root.getChildren().addAll(borderPane);
stage.setScene(scene);
stage.show();
}
}
1. Open the empty ComboBox. An empty (blank) entry pops up (I guess this is desired behavior)
2. Add two items to the ComboBox (Add Button).
3. Open the ComboBox and select the 2nd entry (or first)
4. Click Delete Button.
5. Open the ComboBox
=> The ComboBox displays the first added item AND a blank 2nd item, which feels buggy to me.
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import java.util.UUID;
public class TestApp3 extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(final Stage stage) throws Exception {
BorderPane borderPane = new BorderPane();
Scene scene = new Scene(new Group(), 450, 250);
ComboBox<String> myComboBox = new ComboBox<>();
Button add = new Button("Add");
add.setOnAction(event -> myComboBox.getItems().add(UUID.randomUUID().toString()));
Button delete = new Button("Delete");
delete.setOnAction(event -> myComboBox.getItems().remove(myComboBox.getSelectionModel().getSelectedItem()));
Group root = (Group) scene.getRoot();
borderPane.setTop(myComboBox);
borderPane.setCenter(add);
borderPane.setBottom(delete);
root.getChildren().addAll(borderPane);
stage.setScene(scene);
stage.show();
}
}