Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • 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
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

how to open picture in JPanel

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to open picture in JPanel??? I have code but it does not do anything=/
 
Marshal
Posts: 25223
65
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Creating a new JLabel inside your action event is a very strange thing to do. You might be able to make that code work if you subsequently added the JLabel to your GUI, but in your case I would recommend you keep it simple. Use a JLabel which is already part of your GUI to display the picture.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever you add components to an already realized container, you need to call revalidate(). In the case of removing components, it's necessary to additionally repaint() the container.

Since repaint() isn't usually computationally expensive, take the safe path and call both whenever you add or remove components.
 
Bobby Marvikuan
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Darryl Burke wrote:Whenever you add components to an already realized container, you need to call revalidate(). In the case of removing components, it's necessary to additionally repaint() the container.

Since repaint() isn't usually computationally expensive, take the safe path and call both whenever you add or remove components.


cheers a lot!
 
Bobby Marvikuan
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:Creating a new JLabel inside your action event is a very strange thing to do. You might be able to make that code work if you subsequently added the JLabel to your GUI, but in your case I would recommend you keep it simple. Use a JLabel which is already part of your GUI to display the picture.


Thank you!:)
 
Let's get him boys! We'll make him read this tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!