Re: JDialog
Fam. Tamboer wrote:
...My problem is how do I reach that OK-button so when it is
clicked the dialog will disappear?
'Don't' reach it, but simply wait for the result returned
by the JOptionPane. E.G.
<sscce>
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class DisappearingDialog {
public static void main(String[] args) {
Runnable r = new Runnable() {
public void run() {
JFrame f = new JFrame( "Disappearing Dialog" );
f.getContentPane().add(
new JLabel("JFrame", SwingConstants.CENTER) );
f.setMinimumSize( new Dimension(400,300) );
f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
final JDialog dialog = new JDialog(f, "The Dialog");
JButton openOpt = new JButton("Show Option Pane");
openOpt.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent ae) {
int result = JOptionPane.showConfirmDialog(
dialog,
"Close the Dialog?");
if (result==JOptionPane.OK_OPTION) {
dialog.setVisible(false);
}
}
} );
dialog.getContentPane().add( openOpt );
dialog.pack();
dialog.setLocationRelativeTo( f );
dialog.setVisible( true );
}
};
EventQueue.invokeLater(r);
}
}
</sscce>
--
Andrew Thompson
http://www.physci.org/
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-setup/200712/1