Java Swing 的日期选择器 GUI 组件

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

Date Picker GUI component for Java Swing

javaswingdateuser-interfacenetbeans

提问by Lemon Juice

I am sure this question has been asked before, but I could not find the answer. I am seeking for a Date PickerGUI component which I can drag and drop from NetbeansIDE. I found the below.

我确定这个问题以前有人问过,但我找不到答案。我正在寻找一个Date Picker可以从NetbeansIDE 中拖放的GUI 组件。我找到了下面的。

  1. http://toedter.com/software/- This is not free for commercial use.

  2. http://plugins.netbeans.org/plugin/658/jdatechooser-1-2- This has issues, the dates are invisible.

  1. http://toedter.com/software/- 这不是免费的商业用途。

  2. http://plugins.netbeans.org/plugin/658/jdatechooser-1-2- 这有问题,日期不可见。

So anyone know whether there is a free for commercial use Date Pickercomponent for Java, which we can drag and drop from Netbeans?

那么有人知道是否有一个免费的用于商业用途Date Picker的 Java 组件,我们可以从 Netbeans 中拖放它?

回答by Mar Millán

You can use JDatePicker. Download from this link: http://sourceforge.net/projects/jdatepicker/

您可以使用 JDatePicker。从此链接下载:http: //sourceforge.net/projects/jdatepicker/

it's used like other Swing components:

它像其他 Swing 组件一样使用:

UtilDateModel model = new UtilDateModel();
JDatePanelImpl datePanel = new JDatePanelImpl(model);
JDatePickerImpl datePicker = new JDatePickerImpl(datePanel);

frame.add(datePicker);

回答by MadProgrammer

Netbeans will allow you to drag any component that extends from JComponent, so long as the class is within the project's classpath.

Netbeans 将允许您拖动从 扩展的任何组件,JComponent只要该类位于项目的类路径中。

Once the jar file has been linked to your project, you should be able to expand the jar contents (under the libraries node) and drag the class onto the form.

将 jar 文件链接到您的项目后,您应该能够展开 jar 内容(在库节点下)并将类拖到表单上。

I do this for my own custom components (.java files) all the time.

我一直为自己的自定义组件(.java 文件)执行此操作。

If this seems cumbersome, you can also add the components to the Swing component palette.

如果这看起来很麻烦,您还可以将组件添加到 Swing 组件面板。

  • From the Tools menu, select Palette -> Swing/AWT Components
  • Create a new Category for your components
  • Select "Add from Jar..."
  • Select the Jar, make sure that the Jar is within a stable location AND is added to any project that wants to use the components!
  • The wizard will scan the contents and present you with choices you can add, select the components that you actually want
  • Select the category that you want them added to (probably the one you just added) and select "Finish"
  • 从工具菜单中,选择调色板 -> Swing/AWT 组件
  • 为您的组件创建一个新类别
  • 选择“从 Jar 添加...”
  • 选择 Jar,确保 Jar 位于一个稳定的位置并添加到任何想要使用这些组件的项目中!
  • 向导将扫描内容并为您提供可以添加的选项,选择您真正想要的组件
  • 选择您希望将它们添加到的类别(可能是您刚刚添加的类别),然后选择“完成”

In the palette, expand your category (make sure you selected it within the "Palette Manager") and you should all the components

在调色板中,展开您的类别(确保您在“调色板管理器”中选择了它)并且您应该将所有组件

DatePicker

日期选择器

A, general, free to use component library is the SwingLabs, SwingX library, so long as you don't try and sell it, you should be able to use freely, you also get access to the source code, so if you want to add featrues, you should also be able to. I would suggest that if you do, you should notify them and offer what changes you can, so the community can benefit.

A、一般来说,免费使用的组件库是SwingLabs、SwingX 库,只要你不尝试卖掉它,你应该可以免费使用,你也可以访问源代码,所以如果你想添加功能,您也应该可以。我建议如果你这样做了,你应该通知他们并提供你可以做的改变,这样社区才能受益。

The JXDatePickeris highly customisable, but you'll need to get your hands dirty with some code to be the best features...

JXDatePicker是高度可定制的,但你需要用一些代码来弄脏你的手才能成为最好的功能......