예제 #1
0
  /** @return file chooser in dialog */
  public Component getCustomEditor() {
    final JFileChooser chooser = createFileChooser();

    final javax.swing.JDialog dialog =
        new javax.swing.JDialog(
            TopManager.getDefault().getWindowManager().getMainWindow(),
            chooser.getDialogTitle(),
            true);

    // attach cancel also to Escape key
    dialog
        .getRootPane()
        .registerKeyboardAction(
            new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                dialog.setVisible(false);
                dialog.dispose();
              }
            },
            javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0, true),
            javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW);

    dialog.addKeyListener(
        new java.awt.event.KeyAdapter() {
          public void keyPressed(java.awt.event.KeyEvent evt) {
            if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_ESCAPE) {
              dialog.setVisible(false);
              dialog.dispose();
            }
          }
        });

    dialog.getContentPane().setLayout(new java.awt.BorderLayout());
    dialog.getContentPane().add(chooser, java.awt.BorderLayout.CENTER);
    chooser.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            if (JFileChooser.APPROVE_SELECTION.equals(evt.getActionCommand())) {
              File f = chooser.getSelectedFile();
              setValue(f);
              dialog.setVisible(false);
              dialog.dispose();
            } else if (JFileChooser.CANCEL_SELECTION.equals(evt.getActionCommand())) {
              dialog.setVisible(false);
              dialog.dispose();
            }
          }
        });

    HelpCtx.setHelpIDString(dialog.getRootPane(), getHelpCtx().getHelpID());
    return dialog;
  }
 // <editor-fold defaultstate="collapsed" desc=" added ">
 @Override
 public void setVisible(boolean visible) {
   super.setVisible(visible);
   if (visible == true) {
     getContentPane().removeAll();
     initComponents();
     myInit();
     repaint();
   }
 }
예제 #3
0
    public void mouseClicked(MouseEvent e) {
      if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 1) {
        JButton source = (JButton) e.getSource();

        String value = source.getText();
        int day = Integer.parseInt(value);
        calendar.set(Calendar.DAY_OF_MONTH, day);
        Date selectDate = this.getSelectDate();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        MyDateChooseBtn.this.setText(simpleDateFormat.format(selectDate));
        Jtext.setText(simpleDateFormat.format(selectDate));

        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        //        System.out.println(year + "骞�" + month + "鏈�" + day + "鏃�");
        f.dispose();
      }
    }
예제 #4
0
  public void btnChoose_actionPerformed() {
    //            java.awt.Rectangle r = dateField.getBounds();
    //            Point pOnScreen = dateField.getLocationOnScreen();
    java.awt.Rectangle r = Jtext.getBounds();
    Point pOnScreen = Jtext.getLocationOnScreen();

    Point result = new Point(pOnScreen.x, pOnScreen.y + r.height);
    Point powner = owner.getLocation();
    int offsetX = (pOnScreen.x + width) - (powner.x + owner.getWidth());
    int offsetY = (pOnScreen.y + r.height + height) - (powner.y + owner.getHeight());

    if (offsetX > 0) {
      result.x -= offsetX;
    }

    if (offsetY > 0) {
      result.y -= height + r.height;
    }

    javax.swing.JDialog dateFrame = new javax.swing.JDialog();
    dateFrame.setModal(false);
    dateFrame.setUndecorated(true);
    dateFrame.setLocation(result);
    dateFrame.setSize(width, height);

    dateFrame.addWindowListener(
        new WindowAdapter() {
          // 鍦ㄤ换鎰忕殑闈炴棩鏈熼�夋嫨鍖哄崟鍑伙紝鍒欐棩鏈熼�夋嫨缁勪欢灏嗗彉涓洪潪娲诲姩鐘舵�侊紝鑷姩閲婃斁璧勬簮銆�
          public void windowDeactivated(WindowEvent e) {
            javax.swing.JDialog f = (javax.swing.JDialog) e.getSource();
            f.dispose();
          }
        });
    DatePanel datePanel = new DatePanel(dateFrame, parten);
    dateFrame.getContentPane().setLayout(new BorderLayout());
    dateFrame.getContentPane().add(datePanel);
    dateFrame.setVisible(true);
  }