FULL PRODUCT VERSION :
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) Client VM (build 25.45-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows 7 Professional 64-bit Service Pack 1
A DESCRIPTION OF THE PROBLEM :
To get the text in an editable ComboBox selected when it gets focused, I added a listener to the 'focused'-property of the editor inside the ComboBox.
In this listener the editor's 'selectAll' method is called.
I expected the text to be selected when the ComboBox's editor gets the focus, but this doesn't happened.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the provided code. Enter some text inside the ComboBox and switch the focus between the ComboBox's editor and the Button.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
When the editor has the focus the text should be selected
ACTUAL -
The text is not selected when the editor gets the focus.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
BorderPane root = new BorderPane();
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
ComboBox<String> comboBox = new ComboBox<>();
comboBox.setEditable(true);
comboBox.setItems(FXCollections.observableArrayList("eins", "zwei"));
comboBox.focusedProperty().addListener((ov, o, n) -> {
if (n) {
System.out.println("Focus!");
comboBox.getEditor().selectAll();
}
});
Button button = new Button("Click me!");
VBox vBox = new VBox();
vBox.getChildren().addAll(comboBox, button);
root.setCenter(vBox);
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
---------- END SOURCE ----------