Skip to content

Instantly share code, notes, and snippets.

@afinlay5
Created May 22, 2020 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afinlay5/3ccfd54ef47d159e5fbd7b9f9fce3cbd to your computer and use it in GitHub Desktop.
Save afinlay5/3ccfd54ef47d159e5fbd7b9f9fce3cbd to your computer and use it in GitHub Desktop.
JavaFX 8 -> 11 ComboBox Regression
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.application.Application;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.scene.input.KeyCode;
import javafx.geometry.Insets;
public class FXTestCB extends Application {
public static void main (String[] args) { launch(args); }
public void start(Stage stage) {
VBox root = new VBox();
ComboBox<String> cb = new ComboBox<>();
cb.setPromptText("Sample");
cb.getItems().addAll("Jane", "Mary", "Doe");
Button btn = new Button ("OK");
cb.setOnKeyPressed(kp ->
{
if (kp.getCode().equals(KeyCode.F5)) {
cb.getSelectionModel().clearSelection();
//cb.getItems().clear();
btn.requestFocus();
}
}
);
btn.setOnAction( ae -> cb.getItems().addAll("Jane", "Mary", "Doe") );
root.getChildren().addAll(cb, btn);
stage.setScene( new Scene (root, 100, 100) );
stage.show();
}
}
@afinlay5
Copy link
Author

afinlay5 commented May 22, 2020

Clearing the selected item AND clearing the items list, individually, both cause the prompt text to disappear in JavaFX 11. This is not the case in JavaFX 8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment