• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Creating pop-up messages

 
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?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE 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 ]
 
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
 
Author
Posts: 974
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.
 
Bartender
Posts: 11445
18
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • 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!