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); }
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); }