java 摆动时间选择器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7579577/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 20:34:26  来源:igfitidea点击:

Swing time picker

javaswingdatetime

提问by Fsero

Im looking for a pretty and decent time picker component. There are a lot of alternatives for date picking on Swing but no for time.

我正在寻找一个漂亮而体面的时间选择器组件。在 Swing 上选择日期有很多选择,但没有时间选择。

I've seen nice Date/Time components picking on JQuery ( for example: http://trentrichardson.com/examples/timepicker/). There is something similar on Swing?

我见过很好的日期/时间组件在 JQuery 上挑选(例如:http: //trentrichardson.com/examples/timepicker/)。Swing 上有类似的东西吗?

Thanks in advance.

提前致谢。

回答by Ashwini Raman

回答by Costis Aivalis

I think you will like the ease of JCalendar. It offers a JDateChooser, a JDayChooseror a JSpinnField, written by Kai Toedter', available here: JCalendar 1.4.

我想您会喜欢 JCalendar 的易用性。它提供了由 Kai Toedter 编写的a JDateChooser、 aJDayChooser或 a JSpinnField,可在此处获得:JCalendar 1.4

JDateChooser Example

JDateChooser 示例

You can get your dates like this:

你可以这样得到你的日期:

java.util.Date fromDate = jDateChooser1.getDate();

JSpinnField lets you set max and min values easily:

JSpinnField 可让您轻松设置最大值和最小值:

jSpinField1.setMaximum(59);
jSpinField1.setMinimum(0);

回答by BlakeTNC

I would suggest the TimePickercomponent of the LGoodDatePickerlibrary. The time can be chosen with the (default) "drop down" menu, with (optional) "spinner" style buttons, or both.

我建议使用LGoodDatePicker库的TimePicker组件。可以使用(默认)“下拉”菜单、(可选)“微调”样式按钮或两者选择时间。

Fair disclosure: I'm the primary developer.

公平披露:我是主要开发人员。

The TimePicker can be customized with optional settings. A few of the settings are the language (locale), default times in the drop down menu, fonts and colors, display/menu/parsing formats, 12 or 24 hour clock, seconds or nanoseconds precision, and so forth.

可以使用可选设置自定义 TimePicker。一些设置是语言(区域设置)、下拉菜单中的默认时间、字体和颜色、显示/菜单/解析格式、12 或 24 小时制、秒或纳秒精度等。

The library also includes the DatePicker and DateTimePicker components. All three components are easy to use. (They can each be instantiated with a single line of code.)

该库还包括 DatePicker 和 DateTimePicker 组件。所有三个组件都易于使用。(它们都可以用一行代码实例化。)

I've pasted screenshots of the components and the demo application below.

我在下面粘贴了组件和演示应用程序的屏幕截图。

Project Home page: https://github.com/LGoodDatePicker/LGoodDatePicker.

项目主页:https: //github.com/LGoodDatePicker/LGoodDatePicker

DateTimePicker screenshot

日期时间选择器截图

( Click to enlarge the demo screenshot. ) Demo screenshot

(点击放大演示截图。) 演示截图