pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

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

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

問題描述

限時送ChatGPT賬號..

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

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?

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

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 和按鈕組件總是隱藏,但我還是不知道如何在不隱藏的情況下做到這一點彈出窗口也是如此.此外,我可能需要獲得彈出窗口的邊界以在此替代方法中適當地管理高度和寬度,這似乎又不是那么容易.

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 的彈出內容.有關實現,請參閱此演示:

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.[...] 實現.(參見 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();

您還可以通過向關聯屬性添加 ChangeListener 來監聽值更改:

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模板網!

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

相關文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉換為公歷?)
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 日之前日期的日歷到日期轉換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當前星期幾的值)
主站蜘蛛池模板: 间苯二酚,间苯二酚厂家-淄博双和化工| ET3000双钳形接地电阻测试仪_ZSR10A直流_SXJS-IV智能_SX-9000全自动油介质损耗测试仪-上海康登 | 高压分散机(高压细胞破碎仪)百科-北京天恩瀚拓 | 钢格板_钢格栅_格栅板_钢格栅板 - 安平县鑫拓钢格栅板厂家 | 游泳池设备安装工程_恒温泳池设备_儿童游泳池设备厂家_游泳池水处理设备-东莞市君达泳池设备有限公司 | 有机废气处理-rto焚烧炉-催化燃烧设备-VOC冷凝回收装置-三梯环境 | 北京开业庆典策划-年会活动策划公司-舞龙舞狮团大鼓表演-北京盛乾龙狮鼓乐礼仪庆典策划公司 | 全国国际化学校_国际高中招生_一站式升学择校服务-国际学校网 | 不锈钢搅拌罐_高速搅拌罐厂家-无锡市凡格德化工装备科技有限公司 | NM-02立式吸污机_ZHCS-02软轴刷_二合一吸刷软轴刷-厦门地坤科技有限公司 | 蒜肠网-动漫,二次元,COSPLAY,漫展以及收藏型模型,手办,玩具的新媒体.(原变形金刚变迷TF圈) | 骨龄仪_骨龄检测仪_儿童骨龄测试仪_品牌生产厂家【品源医疗】 | 锂电池生产厂家-电动自行车航模无人机锂电池定制-世豹新能源 | 整合营销推广|营销网络推广公司|石家庄网站优化推广公司|智营销 好物生环保网、环保论坛 - 环保人的学习交流平台 | 安德建奇火花机-阿奇夏米尔慢走丝|高维|发那科-北京杰森柏汇 | 交变/复合盐雾试验箱-高低温冲击试验箱_安奈设备产品供应杭州/江苏南京/安徽马鞍山合肥等全国各地 | 座椅式升降机_无障碍升降平台_残疾人升降平台-南京明顺机械设备有限公司 | CCC验厂-家用电器|服务器CCC认证咨询-奥测世纪| 智能电表|预付费ic卡水电表|nb智能无线远传载波电表-福建百悦信息科技有限公司 | 重庆波纹管|重庆钢带管|重庆塑钢管|重庆联进管道有限公司 | 双杰天平-国产双杰电子天平-美国双杰-常熟双杰仪器 | 水冷式工业冷水机组_风冷式工业冷水机_水冷螺杆冷冻机组-深圳市普威机械设备有限公司 | 手板_手板模型制作_cnc手板加工厂-东莞天泓| 海水晶,海水素,海水晶价格-潍坊滨海经济开发区强隆海水晶厂 | 汽车水泵_汽车水泵厂家-瑞安市骏迪汽车配件有限公司 | 精密机械零件加工_CNC加工_精密加工_数控车床加工_精密机械加工_机械零部件加工厂 | 环球周刊网| 不锈钢法兰-碳钢法兰-法兰盘生产加工厂家-[鼎捷峰]-不锈钢法兰-碳钢法兰-法兰盘生产加工厂家-[鼎捷峰] | 成都亚克力制品,PVC板,双色板雕刻加工,亚克力门牌,亚克力标牌,水晶字雕刻制作-零贰捌广告 | 利浦顿蒸汽发生器厂家-电蒸汽发生器/燃气蒸汽发生器_湖北利浦顿热能科技有限公司官网 | 北京软件开发_软件开发公司_北京软件公司-北京宜天信达软件开发公司 | 深圳激光打标机_激光打标机_激光焊接机_激光切割机_同体激光打标机-深圳市创想激光科技有限公司 深圳快餐店设计-餐饮设计公司-餐饮空间品牌全案设计-深圳市勤蜂装饰工程 | 工业铝型材生产厂家_铝合金型材配件批发精加工定制厂商 - 上海岐易铝业 | 浙江清风侠环保设备有限公司| 陕西高职单招-陕西高职分类考试网 | 风淋室生产厂家报价_传递窗|送风口|臭氧机|FFU-山东盛之源净化设备 | 隔离变压器-伺服变压器--输入输出电抗器-深圳市德而沃电气有限公司 | 派克防爆伺服电机品牌|国产防爆伺服电机|高低温伺服电机|杭州摩森机电科技有限公司 | 达利园物流科技集团-| 至顶网 | 精密五金加工厂-CNC数控车床加工_冲压件|蜗杆|螺杆加工「新锦泰」 |