【问题标题】:How to clear the JXDatePicker field如何清除 JXDatePicker 字段
【发布时间】:2013-02-28 11:10:22
【问题描述】:

我正在开发一个简单的桌面应用程序 使用 Java 和 NetBeans 7 我有一个 textfield 和一个 textarea 以及一个 jxdatepicker 我有一个清除按钮,可以在需要时清除字段

我用的是

jtextfield.setText("") and 
  jtextArea.setText("")

按照指示清除文本字段和文本区域。 但我的问题是如何清除日期选择器 单击清除按钮时显示一个干净的字段?

【问题讨论】:

    标签: java swing netbeans datepicker swingx


    【解决方案1】:

    基本上:

    picker.setDate(null);
    

    附录:

    深入了解选择器的内部并设置其编辑器的文本是错误的,因为文本仅在编辑器中更新,但未提交到底层模型:

    picker.getEditor().setText("");
    System.out.println(picker.getDate());
    
    // output
    Thu Feb 28 00:00:00 CET 2013 
    
    // output after nulling the date with the appropriate api
    null
    

    【讨论】:

    • 你真的93岁了吗? 0_o。您的个人资料显示您的age = 93
    • @HarryJoy 它不会占用我真正的 103
    【解决方案2】:

    1.这样设置属性。 datePicker.getModel().setValue(null);;

    【讨论】:

      猜你喜欢
      • 2015-12-19
      • 1970-01-01
      • 2014-05-29
      • 2021-09-27
      • 1970-01-01
      • 1970-01-01
      • 2015-01-13
      • 1970-01-01
      • 2017-04-09
      相关资源
      最近更新 更多