• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

How to add image in a pop up

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am trying to create a pop up window that will display an image.

Here is my code so far:



I know the code to make a pop up window that displays a message but I am not sure on how to display an image. Also my second question is: in the pop up window does the image have to be a real image such as a jpeg,png etc. or can I draw it myself within java?

Thank you!
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "pop up window" -- JPopupMenu / Popup / JOptionPane#showMessageDialog(...) / something else ?

If the third named, you can pass an Icon as the message parameter.

does the image have to be a real image such as a jpeg,png etc. or can I draw it myself within java?


Either way, it's a real Image. Don't confuse an Image with the File it may have been loaded from.

You might want to look at the classes BufferedImage and ImageIcon.
 
Marshal
Posts: 64629
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our GUIs forum, where we usually discuss this sort of question.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!