944,185 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 753
  • Java RSS
Oct 26th, 2009
0

Problem in working with images in swing

Expand Post »
I am using this code for displaying images on JPanel, in which i succeeded, but the images are volatile. When i maximize or minimize the frame, it vanishes.

Java Syntax (Toggle Plain Text)
  1. public class ImagePanel extends JPanel{
  2.  
  3. private BufferedImage image;
  4.  
  5. public ImagePanel() {
  6. try {
  7. image = ImageIO.read(new File("image name and path"));
  8. } catch (IOException ex) {
  9. // handle exception...
  10. }
  11. }
  12.  
  13. @Override
  14. public void paintComponent(Graphics g) {
  15. g.drawImage(image, 0, 0, this);
  16.  
  17. }
  18.  
  19. }
Last edited by peter_budo; Sep 2nd, 2011 at 11:30 am. Reason: Not snipped, changing to thread
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tsfaridi is offline Offline
7 posts
since Mar 2009
Oct 26th, 2009
0
Re: Problem in working with images in swing
This belongs in a normal thread, not in a code snippet. And I've experienced the same problem in the past, but I did a lot more debugging than you did. For example, when the window is resized, is your paintComponent method called?
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Oct 26th, 2009
0
Re: Problem in working with images in swing
Thanks! you have shown me a path, i will work on it. Here the issue arises is, i am working on Checkers game, calling the paint method again will not resolve my issue. As the position of pieces will not be the same as initial.
@BestJewSinceJC: Kindly share with me your experience, how did you resolved this problem ??
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tsfaridi is offline Offline
7 posts
since Mar 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: help with a code
Next Thread in Java Forum Timeline: Recording in an applet





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC