The Artima Developer Community
Sponsored Link

Java Answers Forum
Have a problem in Modal dialog

1 reply on 1 page. Most recent reply: Jul 5, 2003 4:02 AM by zenykx

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Renuka

Posts: 1
Nickname: renuka
Registered: Jun, 2003

Have a problem in Modal dialog Posted: Jun 27, 2003 3:52 AM
Reply to this message Reply
Advertisement
Hi,
In my application i have a JDialog having a default ok button. By pressing the button an error dialog will be shown. The problem is pressing the ok button continuously (holding it), will hang the application. Other than using a timer how can i fix this? pl. give me a solution as early as possible... A sample code is given below, having the same scenario.

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/*
* @ (#)TestModal.java
*
* @version $Revision: $
*
* Date Created : Jun 27, 2003
* Latest Modification $Date: 2003 1:02:45 PM $
*
*/

/**
* @author renuka (renuka@i7asia.co.in)
*
* @version $Revision: $ $Date: 2003/04/30 07:02:28 $
*
*/
public class TestModal extends JDialog {

/**
* button for performing some action
*/
private JButton mActionButton = new JButton();

/**
* Default constructor
*/
public TestModal() {
super();
mActionButton.setText("Save");
JPanel panel = new JPanel();
panel.add(mActionButton);
this.getContentPane().add(panel);
mActionBu tton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {
button_actionPerformed();
}
});
this.getRootPane().setDefaultButton(mActionBu tton);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
}

/**
* method invoked when an action is performed on the button
*/
private void button_actionPerformed() {
JOptionPane.showOptionDialog(this,
"Continuously clicking enter will hang the application",
"Title", JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
null,
null);
}

/**
* main method
*
* @param args command line arguments
*/
public static void main(String[] args) {
TestModal modalObject = new TestModal();
modalObject.setSize(100,100);
modalObject.show();
}
}

Thanks and Regards,
R. Renuka


zenykx

Posts: 69
Nickname: zenykx
Registered: May, 2003

Re: Have a problem in Modal dialog Posted: Jul 5, 2003 4:02 AM
Reply to this message Reply
you have a "dirty" solution... set a flag while the second dialog is opened.... and before opening a new one check for this flag.

Flat View: This topic has 1 reply on 1 page
Topic: Practical question Previous Topic   Next Topic Topic: Trivial question about JScrollBar

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use