• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating pop-up messages

 
Kari Nordmann
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the easiest way to create a small popup window like "you win"\"you lose"?
Do I have to make a GUI like with every other window, or is there a quicker way to just insert a short text and an ok-button?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what JDialogs are for.
[ May 14, 2008: Message edited by: Paul Sturrock ]
 
Guido Sautter
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might also give a thought to using one of the static showXyzDialog() methods of JOptionPane.
 
Kari Nordmann
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice, thanks
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kari Nordmann:
What's the easiest way to create a small popup window like "you win"\"you lose"?
Do I have to make a GUI like with every other window, or is there a quicker way to just insert a short text and an ok-button?


It's as simple as
JOptionPane.showMessageDialog(parentComponent, "You win!");

You may pass in null for parentComponent but I strongly
recommend against it. Non-null will not only position the dialog
properly, but will also prevent disasters with things like alt-tabbing.

If you want to specify the String on the title bar, then use a longer form:
JOptionPane.showMessageDialog(parent, "You win!", "titlebar string", JOptionPane.INFORMATION_MESSAGE);

If you don't want the icon in the dialog, use PLAIN_MESSAGE instead of INFORMATION_MESSAGE.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Brian Cole:

If you don't want the icon in the dialog, use PLAIN_MESSAGE instead of INFORMATION_MESSAGE.


I would suggest you do use icons.
INFORMATION_MESSAGE/WARNING displays an exclamation mark (!) which you can use in case of "You win" whereas ERROR displays a cross mark (X) which you can use in case of "You loose".
This has nothing to do with technology, but, at least in my opinion, it adds a little touch to your application. From the usability point of view these little things always count.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!