清除datechooser中的日期

时间:2015-09-02 06:36:07

标签: java swing jcalendar

我正在使用jcalendar-1.2.2 jar中的日期选择器。如何清除datechooser日期字段中的日期?

package com.multiasset.manualorderentry.gui.components;

import java.awt.FlowLayout;
import java.text.ParseException;
import java.util.Date;

import javax.swing.JLabel;
import javax.swing.JPanel;

import com.indigo.utils.Log;
import com.multiasset.manualorderentry.constants.ManualOrderConstants;
import com.toedter.calendar.JDateChooser;

@SuppressWarnings("serial")
public class FixingDatePanel extends JPanel{
  private JDateChooser fixingDateChooser;
  private JLabel fixingDateLabel;
  private String labelText;

  public FixingDatePanel(String labelText) {
   this.labelText = labelText;
   initComponents();
   layoutComponents();

  }

  private void initComponents() {
    fixingDateLabel = new JLabel(labelText);
    fixingDateLabel.setPreferredSize(ManualOrderConstants.LABEL_DIMENSION);

    fixingDateChooser = new com.toedter.calendar.JDateChooser();
    fixingDateChooser.setPreferredSize(ManualOrderConstants.EDITOR_DIMENSION);
    fixingDateChooser.setDateFormatString("yyyyMMdd");
    fixingDateChooser.setDate(new Date());
  }

  private void layoutComponents() {
  setLayout(new FlowLayout(FlowLayout.LEFT, 5, 0));
   add(fixingDateLabel);
   add(fixingDateChooser);

  }

  public void setEnabled(boolean enabled) {
    fixingDateLabel.setEnabled(enabled);
    fixingDateChooser.getSpinner().setEnabled(enabled);
  }

  public void setFixingDate(String fixingDate) {
    try {
      Date date = ManualOrderConstants.formatter.parse(fixingDate);
      fixingDateChooser.setDate(date);
    } catch (ParseException e) {
      Date date = new Date();
      fixingDateChooser.setDate(date);
      Log.error("FixingDatePanel", "setFixingDate", e);
    }
  }

  public String getFixingDate(){
    Date date = fixingDateChooser.getDate();
    String fixingDate = ManualOrderConstants.formatter.format(date);
    return fixingDate;
  }

  public Date getDate(){
    return fixingDateChooser.getDate();
  }
}

我有一个带标签和日期追踪器的JPanel。基于某些条件,我想做panel.setEnabled(false)和panel.setFixingDate(“”)。像这样清除田地。

我不能使用how to clear JDateChooser field?因为我使用jcalendar-1.2.2 jar。它没有像setCalendar这样的方法。

0 个答案:

没有答案