示例#1
0
  private void updateCalendar() {
    Calendar cal = model.getSelection();
    if (!"".equals(dayField.getText())) {
      cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dayField.getText()));
    }

    if (!"".equals(monthField.getText())) {
      // Calendar month starts at 0
      cal.set(Calendar.MONTH, Integer.parseInt(monthField.getText()) - 1);
    }

    if (!"".equals(yearField.getText())) {
      cal.set(Calendar.YEAR, Integer.parseInt(yearField.getText()));
    }
    model.setSelection(cal);
  }
示例#2
0
 public void setCalendar(Calendar cal) {
   // this.cal = cal;
   dayField.setText(Integer.toString(cal.get(Calendar.DAY_OF_MONTH)));
   monthField.setText(Integer.toString(cal.get(Calendar.MONTH) + 1));
   yearField.setText(Integer.toString(cal.get(Calendar.YEAR)));
   model.setSelection(cal);
 }
示例#3
0
  public DateFieldEditor(CalendarComboBoxModel mod) {
    model = mod;
    dayField = new BoundedTextField(MAX_DAY_SIZE, 31, this);
    monthField = new BoundedTextField(MAX_MONTH_SIZE, 12, this);
    yearField = new BoundedTextField(MAX_YEAR_SIZE, 2099, this);

    dayField.setText(Integer.toString(model.getSelection().get(Calendar.DAY_OF_MONTH)));
    monthField.setText(Integer.toString(model.getSelection().get(Calendar.MONTH) + 1));
    yearField.setText(Integer.toString(model.getSelection().get(Calendar.YEAR)));

    dayField.setHorizontalAlignment(SwingConstants.CENTER);
    monthField.setHorizontalAlignment(SwingConstants.CENTER);
    yearField.setHorizontalAlignment(SwingConstants.CENTER);
    dayField.setBorder(new EmptyBorder(0, 0, 0, 0));
    monthField.setBorder(new EmptyBorder(0, 0, 0, 0));
    yearField.setBorder(new EmptyBorder(0, 0, 0, 0));
    dayField.setMargin(new Insets(0, 0, 0, 0));
    monthField.setMargin(new Insets(0, 0, 0, 0));
    yearField.setMargin(new Insets(0, 0, 0, 0));

    buildPanel();

    timeField.setBackground(Color.white);
  }