Created
May 22, 2020 13:41
-
-
Save afinlay5/3ccfd54ef47d159e5fbd7b9f9fce3cbd to your computer and use it in GitHub Desktop.
JavaFX 8 -> 11 ComboBox Regression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.