Last active
February 10, 2016 09:52
-
-
Save manuel-mauky/b5c52dc5ba091f436f1e to your computer and use it in GitHub Desktop.
ComboBox Eventhandling when ENTER is pressed
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.application.Application; | |
import javafx.event.EventHandler; | |
import javafx.event.EventType; | |
import javafx.scene.Scene; | |
import javafx.scene.control.ComboBox; | |
import javafx.scene.control.TextField; | |
import javafx.scene.input.KeyEvent; | |
import javafx.scene.layout.VBox; | |
import javafx.stage.Stage; | |
import java.util.function.BiConsumer; | |
import java.util.function.Function; | |
public class Testpp extends Application { | |
public static void main(String... args) { | |
launch(args); | |
} | |
@Override | |
public void start(Stage primaryStage) throws Exception { | |
ComboBox<String> cb = new ComboBox<>(); | |
cb.getItems().addAll("Test", "hello", "world"); | |
cb.addEventFilter(KeyEvent.KEY_RELEASED, event -> System.out.println("combobox filter")); | |
cb.addEventHandler(KeyEvent.KEY_RELEASED, event -> System.out.println("combobox handler")); | |
TextField tf = new TextField(); | |
tf.addEventFilter(KeyEvent.KEY_RELEASED, event -> System.out.println("textfield filter")); | |
tf.addEventHandler(KeyEvent.KEY_RELEASED, event -> System.out.println("textfield handler")); | |
VBox root = new VBox(cb, tf); | |
Scene scene = new Scene(root); | |
scene.addEventFilter(KeyEvent.KEY_RELEASED, event -> System.out.println("scene filter")); | |
scene.addEventHandler(KeyEvent.KEY_RELEASED, event -> System.out.println("scene handler")); | |
primaryStage.setScene(scene); | |
primaryStage.show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment