• Post Reply Bookmark Topic Watch Topic
  • New Topic

does repaint() call paintComponent() ?

 
Saurabh M Sirdeshmukh
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Friends,
I want to know does repaint() call the paintComponent() method internally on the same component we are operating.
Here's the snippet of my code:

class MyPanel extends JPanel{

//som code

//on clicking a button in panel change the panel color

ActionListener aListener= new ActionListener(){

public void actionPerformed(ActionEvent ae){
setbackground(Color.BLUE); // change the color of the panel
repaint();
}
};

//overriden paintComponent
public void paintComponent(Graphics g){
System.out.println("Enter paintComponent()");
super.paintComponent(g);
System.out.println("Exit paintComponent()");
}

}

what i expect is: to have

Enter paintComponent()
Exit paintComponent() on standard output when i click some button on the panel.
I have overriden the paintComponent() n wanna know if repaint() calls it. but i didn't get the above expected output.
Lemme Know
Thanks
 
Campbell Ritchie
Marshal
Posts: 52558
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inside your Java installation folder you will find a file called src.zip. Unzip that, find the java folder, then the awt folder, then the Component class, then the repaint() method, and you can see how it works.
It may be quicker, however, to read the API documentation.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!