Created
August 31, 2015 13:15
-
-
Save vdemeester/5e582bd946da4d0fab94 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| ComboBoxJDK60.install(scene); // Setup the global focus listener |
This file contains hidden or 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
| package fr.bca.nap.jfx; | |
| import javafx.scene.Node; | |
| import javafx.scene.Scene; | |
| import javafx.scene.control.ComboBox; | |
| import javafx.stage.Stage; | |
| /** | |
| * Fix behaviour for ComboBox on jdk 8_60 (regression). Setting up a Globale Node focus listener.. | |
| */ | |
| public class ComboBoxJDK60 { | |
| public static void install(Scene scene) { | |
| scene.focusOwnerProperty().addListener((observable, oldValue, newValue) -> { | |
| // On focus in (should not be needed) | |
| // handleValue(newValue); | |
| // On focus out | |
| handleValue(oldValue); | |
| }); | |
| } | |
| private static void handleValue(Node nodeValue) { | |
| if (nodeValue != null && nodeValue instanceof ComboBox) { | |
| ComboBox comboBox = (ComboBox) nodeValue; | |
| if (comboBox.isEditable()) { | |
| String value = comboBox.getEditor().getText(); | |
| comboBox.setValue(comboBox.getConverter().fromString(value)); | |
| } | |
| } | |
| } | |
| public static void install(Stage stage) { | |
| install(stage.getScene()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment