ov7a
ov7a

Reputation: 1594

How to disable hiding of combobox popup in JavaFX8?

Is there a way to constantly show combobox popup? The question was about datepicker, but it is a descendant of combobox. I want to call show() method of combobox and then constantly show it until stage is closed. The best thing that it got till now is

    showingProperty().addListener({ ov, old, newValue ->
        if (!newValue) this.show()
    })

It kinda works, but it hides popup and then shows it, and that is inconvinient.

Upvotes: 1

Views: 1893

Answers (2)

Oliver Jan Krylow
Oliver Jan Krylow

Reputation: 1725

The bad solution

Take the popup content out of the date picker skin and use it like any other node. Note that the date picker itself must have been rendered as part of the scene at least once for the skin to have been initialized. There may be a more clever way to initialize the skin.

final DatePicker datePicker = new DatePicker();
final StackPane root = new StackPane( datePicker );
final Scene scene = new Scene( root, 250, 200 );
primaryStage.setScene( scene );
primaryStage.show();

datePicker.setVisible( false );
datePicker.setManaged( false );

final com.sun.javafx.scene.control.skin.DatePickerSkin skin = (com.sun.javafx.scene.control.skin.DatePickerSkin) datePicker.getSkin();
root.getChildren().add( skin.getPopupContent() );

Full example code at github.

The good solution

Use a control made specificly for your purpose, like CalendarPicker from JFXtras.

enter image description here

http://jfxtras.org/

Upvotes: 2

Jur Clerkx
Jur Clerkx

Reputation: 698

If you could override the hide() method of the ComboBoxBase method, you would be able to prevent the control from closing. You would have to make a new class, like alwaysOpenDatePicker and let it extend the javafx scene datapicker class. In that class you could override the hide() method, in which you would do nothing.

I'm not sure if this would work, I'm just thinking out loud. I guess it's worth a try, let me know if it worked :).

And a link to the ComboBoxBase page: https://docs.oracle.com/javafx/2/api/javafx/scene/control/ComboBoxBase.html

Upvotes: 0

Related Questions