Link to home
Start Free TrialLog in
Avatar of zaphod_beeblebrox
zaphod_beeblebrox

asked on

Creating a dialog box

Hi Experts

I am trying to create a dialog box that displays an information message on the screen (i.e. one that does not need the user to react to it, or close it, or click on anything), but which also lets the program continue in the background. I have been able to create dialog boxes before but they always need the user to either close the window or click on a button and will suspend the program until the get a response.

I'm after something simple like this:

informationbox.open("I'm doing (whatever it is)");
Do the process
informationbox.close();

All the sites I have gone to explain how to create dialog boxes but this not what I want. Any suggestions?

Avatar of radarsh
radarsh

JOptionPane.showMessageDialog should be used

________
radarsh
Avatar of CEHJ
JDialog d = new JDialog(yourFrame);
d.setModel(false);
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
   JOptionPane pane = new JOptionPane(message);
    JDialog dialog = pane.createDialog(parentComponent, title);
    dialog.setModel(false);
    dialog.setVisible(true);

    // do your stuff

    dialog.setVisible(false);
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zaphod_beeblebrox

ASKER

Thanks CEHJ and Objects both excellent answers. I did not believe how simple it was -- just make the dialog box non modal!!!

Works great thanks again guys for your most excellent answers
:-)
Hi zaphod_beeblebrox,

I am not sure whether you can do this:

You can activate the GlassPane of your component, instead of showing a dialog box. Place you message on the glasspane. Actvitating the glasspane is like showing a splash screen in the application, application runs and user input is blocked. Once the application finishes its job, hide the glasspane. All the user input consumed by the glasspane is directed to the application.

yourcomponent.getRootPane().getGlassPane().setVisible(true);
//the application does the required work
yourcomponent.getRootPane().getGlassPane().setVisible(false);

Have a look at this link from the java tutorial: http://java.sun.com/docs/books/tutorial/uiswing/components/rootpane.html

Cheers!
glad I could help :)