如何禁用隐藏combobox弹出在JavaFX8? [英] How to disable hiding of combobox popup in JavaFX8?

查看:330
本文介绍了如何禁用隐藏combobox弹出在JavaFX8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法不断显示combobox弹出窗口?问题是关于datepicker,但它是combobox的后代。我想调用combobox的show()方法,然后不断显示,直到阶段关闭。
现在最好的是

 显示属性addListener({ov,old,newValue  - > 
if(!newValue)this.show()
})



解决方案

不好的解决方案



从日期选择器皮肤中取出弹出内容,并像任何其他节点一样使用它。注意,日期选择器本身必须已经被渲染为场景的一部分,至少一次已经对皮肤进行了初始化。可能有更聪明的方式来初始化皮肤。

  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());

完整



http://jfxtras.org/


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.

解决方案

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.

http://jfxtras.org/

这篇关于如何禁用隐藏combobox弹出在JavaFX8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆