Exemplo n.º 1
0
  private JXDatePicker createDatePicker(Date initialDate) {
    final JXDatePicker dp = new JXDatePicker(initialDate);
    dp.setFormats(PhotoCopyToolPanel.DATE_PICKER_FORMAT);
    dp.setEditable(true);
    dp.addActionListener(
        new ActionListener() {
          long lastTime = dp.getDate() == null ? -1 : dp.getDate().getTime();

          @Override
          public void actionPerformed(ActionEvent e) {
            Date d = dp.getDate();
            long t = -1;
            if (d != null) t = d.getTime();

            if (t != lastTime) {
              lastTime = t;
              if (imagesLoaded) selection = getSelectedImages(SelectImageDialog.this);
              loadImagesAsync();
            }
          }
        });
    dp.getEditor()
        .addFocusListener(
            new FocusAdapter() {
              @Override
              public void focusLost(FocusEvent e) {
                try {
                  dp.commitEdit();
                } catch (ParseException pe) {
                }
              }
            });
    return dp;
  }
 public void setEditable(boolean editable) {
   if (dataComponent instanceof JTextComponent) {
     ((JTextComponent) dataComponent).setEditable(editable);
   } else if (dataComponent instanceof JScrollPane) {
     Component subComponent = ((JScrollPane) dataComponent).getViewport().getView();
     if (subComponent instanceof JTextComponent) {
       ((JTextComponent) subComponent).setEditable(editable);
     }
   } else if (dataComponent instanceof JXDatePicker) {
     ((JXDatePicker) dataComponent).setEditable(editable);
   } else {
     dataComponent.setEnabled(editable);
   }
 }