什么是好的 Java 日期选择器 Swing GUI 小部件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1339354/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are good Java date-chooser Swing GUI widgets?
提问by oxbow_lakes
What are good Java Swing date-chooser components? So far I've only really found these 2:
什么是好的 Java Swing 日期选择器组件?到目前为止,我只真正找到了这两个:
JCalendar
- this one is pretty good as it uses the underlying look and feel.JXMonthView
in the SwingXproject - not so good as it uses its own look and feel
Both of these look a bit clunky when compared with some I've seen on web-pages. For example, it might be nice to see multiple monthsat the same time. Does anyone know of any other good widgets out there?
与我在网页上看到的一些相比,这两个看起来都有些笨拙。例如,同时看到多个月可能会很好。有谁知道那里有其他好的小部件吗?
采纳答案by Abel Morelos
Recently I found and use the Microba DatePicker (http://microba.sourceforge.net/) for a personal project involving Swing GUIs, and I actually I really liked the way this control is implemented. Besides, the license is BSD, so you will be able to customize the control and use it for commercial purposes if you need to do so.
最近我发现并使用 Microba DatePicker ( http://microba.sourceforge.net/) 用于涉及 Swing GUI 的个人项目,实际上我真的很喜欢这个控件的实现方式。此外,许可证是 BSD,因此如果您需要,您将能够自定义控件并将其用于商业目的。
回答by tuler
There is also NachoCalendar.
回答by fencingCode
I'm often late but the best i've seen is : JDatePicker
我经常迟到,但我见过的最好的是:JDatePicker
(What has surprised me : week start with Sunday - like many Calendar and by the way Sunday is day 0 in Java - but you can edit the source and recompile to get it start with Monday instead ;-) )
(让我感到惊讶的是:一周从星期日开始 - 就像许多日历一样,顺便说一下,星期天是 Java 中的第 0 天 - 但您可以编辑源代码并重新编译以使其从星期一开始;-))
回答by Ajinkya Jagtap
jDateChooser which comes with jCalendar is the best component for date: Following is the way to get date from date picker:
jCalendar 附带的 jDateChooser 是日期的最佳组件:以下是从日期选择器获取日期的方法:
//dat is name given to datepicker component
int day=dat.getJCalendar().getDayChooser().getDay();
int month=dat.getJCalendar().getMonthChooser().getMonth();
int year=dat.getJCalendar().getYearChooser().getYear();
String dateNow=year+"/"+month+"/"+day;
System.out.println(dateNow);
//***************************************************
//For setting date of date picker:
dat.setDateFormatString("dd-MM-yyyy");
Calendar currentDate = Calendar.getInstance();
dat.setDate(currentDate.getTime());
回答by BlakeTNC
I've tried most of the date pickers out there.
I would suggest LGoodDatePicker.
我已经尝试了大多数日期选择器。
我建议LGoodDatePicker。
https://github.com/LGoodDatePicker/LGoodDatePicker
https://github.com/LGoodDatePicker/LGoodDatePicker
Fair disclosure: I am the primary developer.
公平披露:我是主要开发人员。
Here is a general feature list (as adapted from Github):
这是一个通用功能列表(改编自 Github):
- Automatic internationalization.
- Uses the (new) standard Java 8 time package. Also called "java.time" or "JSR-310".
- Automatic validation of dates.
- Fonts and colors can be changed.
- Optional highlight policies and veto policies.
- Relatively compact source code (3 core classes).
- Creating a DatePicker requires only one line of code.
- Demo program and code samples included.
- Good Javadocs.
- Open source license.
- 自动国际化。
- 使用(新)标准 Java 8 时间包。也称为“java.time”或“JSR-310”。
- 日期的自动验证。
- 可以更改字体和颜色。
- 可选的高亮政策和否决政策。
- 相对紧凑的源代码(3 个核心类)。
- 创建 DatePicker 只需要一行代码。
- 包括演示程序和代码示例。
- 很好的 Javadoc。
- 开源许可证。
Screenshots below:
截图如下: