private void initialize(final Component customComponent, final Validator validator) { getRootPane().setDefaultButton(okCancelPanel.getButton("OK")); this.customComponent = customComponent; getContentPane().setLayout(new BorderLayout()); getContentPane().add(customComponent, BorderLayout.CENTER); okCancelPanel.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (okCancelPanel.wasOKPressed() && validator != null) { String errorMessage = validator.validateInput(customComponent); if (errorMessage != null) { JOptionPane.showMessageDialog( OKCancelDialog.this, errorMessage, getTitle(), JOptionPane.ERROR_MESSAGE); return; } } setVisible(false); } }); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { okCancelPanel.setOKPressed(false); } }); getContentPane().add(okCancelPanel, BorderLayout.SOUTH); pack(); // Don't centre dialog until its size has been determined // i.e. after calling #pack [Jon Aquino 2005-03-09] GUIUtil.centreOnWindow(this); }
/* (non-Javadoc) * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent) */ public void keyReleased(KeyEvent e) { if (!jtfDesc.getText().trim().equals("")) { // $NON-NLS-1$ okp.getOKButton().setEnabled(true); } else { okp.getOKButton().setEnabled(false); } }
/** Constructor */ public QualityFeedbackWizard() { super(Main.getWindow(), Messages.getString("JajukJMenuBar.19")); // $NON-NLS-1$ getContentPane().setPreferredSize(new Dimension(600, 250)); // From jlFrom = new JLabel(Messages.getString("QualityFeedbackWizard.1")); // $NON-NLS-1$ jlFrom.setToolTipText(Messages.getString("QualityFeedbackWizard.2")); // $NON-NLS-1$ jtfFrom = new JTextField(); jtfFrom.setToolTipText(Messages.getString("QualityFeedbackWizard.2")); // $NON-NLS-1$ // Description jlDesc = new JLabel(Messages.getString("QualityFeedbackWizard.3")); // $NON-NLS-1$ jlDesc.setToolTipText(Messages.getString("QualityFeedbackWizard.4")); // $NON-NLS-1$ jtfDesc = new JTextField(); jtfDesc.setToolTipText(Messages.getString("QualityFeedbackWizard.4")); // $NON-NLS-1$ jtfDesc.addKeyListener(this); // Details jlDetail = new JLabel(Messages.getString("QualityFeedbackWizard.5")); // $NON-NLS-1$ jlDetail.setToolTipText(Messages.getString("QualityFeedbackWizard.6")); // $NON-NLS-1$ jtaDetail = new JTextArea(); jtaDetail.setToolTipText(Messages.getString("QualityFeedbackWizard.6")); // $NON-NLS-1$ okp = new OKCancelPanel(this); okp.getOKButton().setEnabled(false); jpMain = new JPanel(); int iXSeparator = 10; int iYSeparator = 20; double[][] dSize = { {iXSeparator, 0.3, iXSeparator, 0.7, iXSeparator}, {iYSeparator, 20, iYSeparator, 20, iYSeparator, 60, 3 * iYSeparator, 20, iYSeparator} }; jpMain.setLayout(new TableLayout(dSize)); jpMain.add(jlFrom, "1,1"); // $NON-NLS-1$ jpMain.add(jtfFrom, "3,1"); // $NON-NLS-1$ jpMain.add(jlDesc, "1,3"); // $NON-NLS-1$ jpMain.add(jtfDesc, "3,3"); // $NON-NLS-1$ jpMain.add(jlDetail, "1,5"); // $NON-NLS-1$ jpMain.add(jtaDetail, "3,5"); // $NON-NLS-1$ jpMain.add(okp, "3,7"); // $NON-NLS-1$ getContentPane().add(jpMain); addWindowListener( new WindowAdapter() { public void windowActivated(WindowEvent e) { jtfFrom.requestFocusInWindow(); } }); getRootPane().setDefaultButton(okp.getOKButton()); }
public boolean wasOKPressed() { return okCancelPanel.wasOKPressed(); }