Ejemplo n.º 1
0
 public void setVisible(boolean visible) {
   pack();
   if (centered) {
     Dimension frameSize = getParent().getSize();
     Point frameLoc = getParent().getLocation();
     Dimension mySize = getSize();
     int x, y;
     x = frameLoc.x + (frameSize.width / 2) - (mySize.width / 2);
     y = frameLoc.y + (frameSize.height / 2) - (mySize.height / 2);
     setBounds(x, y, getSize().width, getSize().height);
   }
   super.setVisible(visible);
 }
Ejemplo n.º 2
0
 @Override
 public void actionPerformed(java.awt.event.ActionEvent e) {
   try {
     PropertyEditor propEd = property.getPropertyEditor();
     propEd.setValue(property.getValue());
     final Component custEditor = propEd.getCustomEditor();
     Object[] options = buttons();
     DialogDescriptor descriptor =
         new DialogDescriptor(
             custEditor,
             (String) getValue(Action.NAME),
             true,
             options,
             DialogDescriptor.CANCEL_OPTION,
             DialogDescriptor.DEFAULT_ALIGN,
             HelpCtx.DEFAULT_HELP,
             (ActionEvent e1) -> {
               try {
                 String action = e1.getActionCommand();
                 switch (action) {
                   case OK_COMMAND:
                     Object value = property.getPropertyEditor().getValue();
                     property.setValue(value);
                     break;
                   case RESTORE_COMMAND:
                     property.restoreDefaultValue();
                     break;
                 }
                 dialog.dispose();
               } catch (Exception ex) {
                 NotifyDescriptor descriptor2 =
                     new NotifyDescriptor.Message(
                         NbBundle.getMessage(PropertyAction.class, "MSG_InvalidValue")); // NOI18N
                 DialogDisplayer.getDefault().notify(descriptor2);
               }
             });
     descriptor.setClosingOptions(new Object[0]);
     dialog = DialogDisplayer.getDefault().createDialog(descriptor);
     dialog.setVisible(true);
     dialog = null;
   } catch (Exception ex) {
     ErrorManager.getDefault().notify(ex);
   }
 }
Ejemplo n.º 3
0
  void showWarning(Frame frame, String warning) {
    warningDialog = new Dialog(frame, "警告", true);
    warningDialog.setSize(200, 100);
    warningDialog.setLayout(new FlowLayout());
    warningDialog.setResizable(false);
    warningDialog.setLocationRelativeTo(frame);

    warningText = new Label(warning);
    warningButton = new Button("确认");

    warningDialog.add(warningText);
    warningDialog.add(warningButton);

    warningDialog.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            warningDialog.setVisible(false);
            warningDialog.dispose();
          }
        });

    warningButton.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            int keyCode = e.getKeyCode();

            if (keyCode == KeyEvent.VK_ENTER) {
              warningDialog.setVisible(false);
              warningDialog.dispose();
            }
          }
        });

    warningButton.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            warningDialog.setVisible(false);
            warningDialog.dispose();
          }
        });

    warningDialog.setVisible(true);
  }
Ejemplo n.º 4
0
 public void run() {
   d.setVisible(true);
   thread = null;
 }