We help IT Professionals succeed at work.

Creating a dialog box

zaphod_beeblebrox
on
Medium Priority
250 Views
Last Modified: 2010-03-31
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?

Comment
Watch Question

Commented:
JOptionPane.showMessageDialog should be used

________
radarsh
CERTIFIED EXPERT
Top Expert 2016

Commented:
JDialog d = new JDialog(yourFrame);
d.setModel(false);
CERTIFIED EXPERT
Top Expert 2016
Commented:
>>d.setModel(false);


should be

d.setModal(false);

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
   JOptionPane pane = new JOptionPane(message);
    JDialog dialog = pane.createDialog(parentComponent, title);
    dialog.setModel(false);
    dialog.setVisible(true);

    // do your stuff

    dialog.setVisible(false);
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
that'll teach me to cut/paste code without checking it for erroers :-D

   JOptionPane pane = new JOptionPane(message);
    JDialog dialog = pane.createDialog(parentComponent, title);
    dialog.setModal(false);
    dialog.setVisible(true);

    // do your stuff

    dialog.setVisible(false);

Author

Commented:
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
CERTIFIED EXPERT
Top Expert 2016

Commented:
:-)

Commented:
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!
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
glad I could help :)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.