JavaFX从DatePicker提取日历弹出窗口/只显示弹出窗口 [英] JavaFX extract calendar-popup from DatePicker / only show popup

查看:2541
本文介绍了JavaFX从DatePicker提取日历弹出窗口/只显示弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为JavaFX应用程序构建CalendarView,仅显示日期(不需要选择)。由于 DatePicker 类有一个漂亮的日历弹出窗口,我想我可能会尝试提取它,以便我已经涵盖了所有的风格问题。



那么有一个简单的方法来提取DatePicker日历弹出框并将其插入新的CalendarView?



我已经看过 show()方法从 ComboBoxBase 类中查看当触发弹出窗口时发生什么,但我不得不承认我不能



或者,我可以考虑简单地编辑DatePicker的方式,只有弹出窗口显示所有的时间与编辑器 - TextField和按钮组件总是隐藏,但我又不能完全弄清楚如何做,而不隐藏弹出窗口以及。另外,我可能需要得到弹出框的边界,以适当地管理高度和宽度在这个交替,这似乎也不是那么容易。

解决方案

您可以从DatePickerSkin获取DatePicker的弹出内容。查看此演示的实现:

  public class DatePickerPopupDemo extends Application {
@Override
public void start (Stage primaryStage){
try {
BorderPane root = new BorderPane();
场景scene = new Scene(root,400,400);
scene.getStylesheets()。add(getClass()。getResource(application.css)。toExternalForm());

DatePickerSkin datePickerSkin = new DatePickerSkin(new DatePicker(LocalDate.now()));
Node popupContent = datePickerSkin.getPopupContent();

root.setCenter(popupContent);

primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e){
e.printStackTrace();
}
}

public static void main(String [] args){
launch(args);
}
}

p>




如果不需要顶栏,您可以查找并隐藏它。

  DatePickerSkin datePickerSkin = new DatePickerSkin(new DatePicker(LocalDate.now())); 
Node popupContent = datePickerSkin.getPopupContent();

//强制css布局传递以确保查找调用工作
popupContent.applyCss();
popupContent.lookup(。month-year-pane)。setVisible(false);

root.setCenter(popupContent);


I'm trying to build an CalendarView for an JavaFX application, to only display dates(no selecting required). Since the DatePicker class has a nice calendar popup I thought I might try to extract it so that I already have all the style-questions covered.

So is there an easy way to extract the DatePicker calendar popup and insert it into a new CalendarView?

I already looked at the show() method from the ComboBoxBase class to see what exactly happens when the popup is triggered but I have to admit I couldn't really get my head around it.

Alternatively I could think about simply edit the DatePicker in a way that only the popup shows all the time with the editor-TextField and button component always hiding, but again I couldn't quite figure out how to do that without hiding the popup as well. Also I would propably need to get the bounds of the popup to approptiately manage height and width in this alternativw, which again seems to be not that easy.

解决方案

You can get the popup content of a DatePicker from a DatePickerSkin. See this demo for an implementation:

public class DatePickerPopupDemo 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());

            DatePickerSkin datePickerSkin = new DatePickerSkin(new DatePicker(LocalDate.now()));
            Node popupContent = datePickerSkin.getPopupContent();

            root.setCenter(popupContent);

            primaryStage.setScene(scene);
            primaryStage.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}


If the top bar is not needed, you can look it up and hide it.

DatePickerSkin datePickerSkin = new DatePickerSkin(new DatePicker(LocalDate.now()));
Node popupContent = datePickerSkin.getPopupContent();

// force a css layout pass to ensure that lookup calls work
popupContent.applyCss();
popupContent.lookup(".month-year-pane").setVisible(false);

root.setCenter(popupContent);

这篇关于JavaFX从DatePicker提取日历弹出窗口/只显示弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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