久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

JavaFX 從 DatePicker 中提取日歷彈出窗口/僅顯示彈出

JavaFX extract calendar-popup from DatePicker / only show popup(JavaFX 從 DatePicker 中提取日歷彈出窗口/僅顯示彈出窗口)
本文介紹了JavaFX 從 DatePicker 中提取日歷彈出窗口/僅顯示彈出窗口的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在嘗試為 JavaFX 應用程序構建 CalendarView,僅顯示日期(無需選擇).由于 DatePicker 類有一個不錯的日歷彈出窗口,我想我可能會嘗試提取它,以便我已經(jīng)涵蓋了所有樣式問題.

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.

那么有沒有一種簡單的方法來提取 DatePicker 日歷彈出窗口并將其插入到新的 CalendarView 中?

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

我已經(jīng)查看了 ComboBoxBase 類中的 show() 方法,以了解觸??發(fā)彈出窗口時究竟發(fā)生了什么,但我不得不承認我真的不能想一想.

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.

或者,我可以考慮簡單地編輯 DatePicker 以一種只有彈出窗口始終顯示的方式,而 editor-TextField 和按鈕組件總是隱藏,但我還是不知道如何在不隱藏的情況下做到這一點彈出窗口也是如此.此外,我可能需要獲得彈出窗口的邊界以在此替代方法中適當?shù)毓芾砀叨群蛯挾龋@似乎又不是那么容易.

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.

推薦答案

您可以從 DatePickerSkin 中獲取 DatePicker 的彈出內(nèi)容.有關實現(xiàn),請參閱此演示:

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

更新:

從 JDK 9 開始,DatePickerSkin 是公共 API 的一部分,不再需要使用封閉的 com.sun.[...] 實現(xiàn).(參見 JavaDoc)

As of JDK 9 DatePickerSkin is part of the Public API and using the closed com.sun.[...] implementation is no longer needed. (See JavaDoc)

另外,如評論中所述,要獲取所選值,您必須訪問從中提取皮膚的 DatePicker(例如,將其保存為變量).

Also, as mentioned in the comments, to get the selected value you have to access the DatePicker from which you extracted the skin (by saving it as an variable for example).

DatePicker datePicker = new DatePicker(LocalDate.now());
DatePickerSkin datePickerSkin = new DatePickerSkin(datePicker);
Node popupContent = datePickerSkin.getPopupContent();
//[...]
LocalDate selectedDate = datePicker.getValue();

您還可以通過向關聯(lián)屬性添加 ChangeListener 來監(jiān)聽值更改:

You can also listen to value-changes by adding a ChangeListener to the associated property:

datePicker.valueProperty().addListener(new ChangeListener<LocalDate>() {
    @Override
    public void changed(ObservableValue<? extends LocalDate> observable, LocalDate oldValue, LocalDate newValue) {
        System.out.println("New Value: " + newValue);
    }
});
//Or using neat lambda
datePicker.valueProperty().addListener((observable, oldValue, newValue) -> {
    System.out.println("New Value: " + newValue);
});

這篇關于JavaFX 從 DatePicker 中提取日歷彈出窗口/僅顯示彈出窗口的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉(zhuǎn)換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉(zhuǎn)換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當前星期幾的值)
主站蜘蛛池模板: 国产精品二区三区在线观看 | hitomi一区二区三区精品 | 色天天综合 | 亚洲免费在线 | 久久久久久免费毛片精品 | 亚洲精品福利在线 | 亚洲精品日韩一区二区电影 | 久久人人网 | 欧美黄色小视频 | 国产探花在线精品一区二区 | 日日操网站 | 欧美日韩综合一区 | 亚洲视频一区在线观看 | 国产精品777一区二区 | 久久新| 久久亚洲一区 | 久久人爽爽人爽爽 | 精品国产乱码久久久久久图片 | 一区二区三区四区不卡视频 | 操操网站 | 中文字幕一区二区三区四区五区 | 亚洲成人精品一区 | 日韩欧美国产一区二区 | 91国内在线观看 | 美女一级毛片 | 亚洲人成一区二区三区性色 | 欧美高清视频一区 | 毛片毛片毛片毛片 | 一级h片| 日本成人免费网站 | 国产一级在线视频 | 成人在线精品视频 | 成人午夜精品 | 成人免费在线观看 | 97人人澡人人爽91综合色 | 亚洲国产精品91 | 最新中文字幕 | 亚洲综合色视频在线观看 | 亚洲高清在线 | 国产精品日日摸夜夜添夜夜av | 久久国产视频一区 |