Problem in working with images in swing

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
tsfaridi tsfaridi is offline Offline Oct 26th, 2009, 2:29 am |
0
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.
Quick reply to this message  
Java Syntax
  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. }
0
BestJewSinceJC BestJewSinceJC is offline Offline | Oct 26th, 2009
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?
 
0
tsfaridi tsfaridi is offline Offline | Oct 26th, 2009
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 ??
 
 

Message:


Similar Threads
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC