NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

repaint() methode on JPanel

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
Schade



Joined: 06 Jan 2017
Posts: 6
Location: France

PostPosted: Wed Jan 11, 2017 10:32 pm    Post subject: repaint() methode on JPanel Reply with quote

Hi !
I made a class "PanImageView" extended from a "JPanel' for showing images.

Code:
public class PanImageView extends javax.swing.JPanel {


So I overwrote the method "paintComponent" like this :

Code:
    @Override
    public void paintComponent(Graphics g){
        super.paintComponent(g);
        if (image!=null){
            g.drawImage(image, 2, 2, this);
        }
       
    }


This working well, but i still get a problem if i add this panel in a another container my image is not visible. Although i call a the repaint() methode.
I tried validate(), revalidate(), dolayout()... don't change anything. The thing, i didn't understand is it's function with the repaint() call when the component is already visible.

So my question is : does i have to wait my component is visible and how i do that ?
Thanks !
Back to top
Schade



Joined: 06 Jan 2017
Posts: 6
Location: France

PostPosted: Thu Jan 12, 2017 8:13 am    Post subject: Reply with quote

After a night of sleep, i understood my mistake : the Buffered image was simply null. Razz Sorry for this useless post.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo