Skip to content

Instantly share code, notes, and snippets.

@vdemeester
Created August 31, 2015 13:15
Show Gist options
  • Select an option

  • Save vdemeester/5e582bd946da4d0fab94 to your computer and use it in GitHub Desktop.

Select an option

Save vdemeester/5e582bd946da4d0fab94 to your computer and use it in GitHub Desktop.
ComboBoxJDK60.install(scene); // Setup the global focus listener
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