2

我使用 JDateChooser 作为 JForm 中的组件。我设置了一个 JButton,它将此表单上的所有字段重置为空白。我对 actionListener 或清除方法没有问题,但不确定如何清除 JDateChooser 组件。

更具体地说,我想知道如何从日期选择器的 JTextField 组件中清除日期,使其为空白。

此外,我想在清除后将此字段设置为当前日期。

4

3 回答 3

5

If you want to clear the JDateChooser field:

JDateChooser dateChooser = new JDateChooser();
dateChooser.setCalendar(null);

This code will set the field to null.

To set the date to today you can use for example:

dateChooser.setDate(new Date())
于 2012-09-10T13:37:41.120 回答
1

如果 dateChooser 是您的 JDateChooser 实例:

dateChooser.setDate(new Date());

编辑:我不确定“设置今天的日期”是什么意思。我假设您的意思是将 JDateChooser 中的日期设置为今天的日期(这就是我的代码所做的)。如果这不是您想要的,请澄清您的问题。

于 2012-07-30T10:50:32.710 回答
0
((JTextField)dateChooser.getDateEditor().getUiComponent()).setText("");
dateChooser.setDate(new Date());
于 2013-04-07T15:13:00.253 回答