Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javafx.application.Application;
- import javafx.application.Platform;
- import javafx.collections.FXCollections;
- import javafx.scene.Scene;
- import javafx.scene.control.ComboBox;
- import javafx.scene.control.Label;
- import javafx.scene.layout.VBox;
- import javafx.stage.Stage;
- public class TestEditableComboBox extends Application{
- @Override
- public void start(Stage primaryStage) throws Exception{
- ComboBox<String> comboBox = new ComboBox<String>(FXCollections.observableArrayList("item 1",
- "item 2",
- "editable"));
- comboBox.setMinWidth(100D);
- comboBox.setMaxWidth(100D);
- comboBox.valueProperty().addListener((observable,
- oldValue,
- newValue) -> {
- if (newValue != null){
- if ("editable".equals(newValue)){
- // JavaFX 2.2: comboBox.setEditable(true);
- Platform.runLater(() -> comboBox.setEditable(true));
- }
- else{
- // JavaFX 2.2: comboBox.setEditable(true);
- Platform.runLater(() -> {
- comboBox.setEditable(false);
- comboBox.getSelectionModel().select(newValue);
- });
- }
- }
- });
- VBox vBox = new VBox(new Label("Broken caret"),
- comboBox);
- Scene scene = new Scene(vBox);
- primaryStage.setScene(scene);
- primaryStage.show();
- }
- public static void main(String[] args){
- Application.launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement