-
Bug
-
Resolution: Fixed
-
P4
-
9
-
9-ea-104
This happens if the editable property is dynamically set to true after the skin is created. The example below compares a combo which is editable from start with a combo that has its editable set via a button.
Run and
- open the popup of the initially editable combo
- click on the arrow: popup is hidden - expected behavior
- click on the button to make the other combo editable
- open popup of other clickup and click on its arrow
- expected: same as first combo, that is hide popup
- actual: popup hidden and shown again
Technical reason is ComboBoxBaseSkin: it registers the mouse handler only if the combo is editable at that time of skin instantiation. Aside: fixing this will make a complete hack around JDK-8150951 even more hacky ;-)
public class ComboEditableArrowHandler extends Application {
private Parent getContent() {
ComboBox box = new ComboBox(FXCollections.observableArrayList("one", "two", "three"));
box.setEditable(true);
box.setValue("initial editable");
ComboBox core = new ComboBox(FXCollections.observableArrayList("one", "two", "three"));
core.setValue("dynamic editable");
Button toggle = new Button("toggle editable");
toggle.setOnAction(e -> {
core.setEditable(!core.isEditable());
});
return new VBox(10, box, core, toggle);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setScene(new Scene(getContent()));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Run and
- open the popup of the initially editable combo
- click on the arrow: popup is hidden - expected behavior
- click on the button to make the other combo editable
- open popup of other clickup and click on its arrow
- expected: same as first combo, that is hide popup
- actual: popup hidden and shown again
Technical reason is ComboBoxBaseSkin: it registers the mouse handler only if the combo is editable at that time of skin instantiation. Aside: fixing this will make a complete hack around JDK-8150951 even more hacky ;-)
public class ComboEditableArrowHandler extends Application {
private Parent getContent() {
ComboBox box = new ComboBox(FXCollections.observableArrayList("one", "two", "three"));
box.setEditable(true);
box.setValue("initial editable");
ComboBox core = new ComboBox(FXCollections.observableArrayList("one", "two", "three"));
core.setValue("dynamic editable");
Button toggle = new Button("toggle editable");
toggle.setOnAction(e -> {
core.setEditable(!core.isEditable());
});
return new VBox(10, box, core, toggle);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setScene(new Scene(getContent()));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}