This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Do certain events make calls to repaint redundant? (Part 2) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Do certain events make calls to repaint redundant? (Part 2)" Watch "Do certain events make calls to repaint redundant? (Part 2)" New topic
Author

Do certain events make calls to repaint redundant? (Part 2)

Colm Dickson
Ranch Hand

Joined: Apr 04, 2009
Posts: 89
Hi again..

I do have an example now of where the circle shape grows in size when the height value is changed due to a scroll bar adjustment but I have no call to the repaint() method in the panel. Why then, when normally I expect to have to call repaint() to update the screen, does this work in my code below without any explicit call to repaint but just changing the scroll value?



my frame class



my main method




Thanks,

Colm
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2152
    
    7
//(necessary imports added


We don't want the comment, we want the imports so we don't have to waste time guessing what they are.

my main method ... my frame class


Don't create separate classes. Put everything in one class. The goal of a SSCCE is to make it "easy for us" (not easy for you) to test your code and help solve the problem.

Why then, when normally I expect to have to call repaint() to update the screen, does this work in my code below without any explicit call to repaint but just changing the scroll value?


Swing components know when to repaint themselves when a property changes. When you change the text of a label the following code is executed:


The first though might be that only the label itself needs to be repainted, but I guess some changes might also affect the parent. Iguess because the size of the component might change the layout of the parent also needs to be considered, which leads to the panel also repainting itself.

Try using the following to see the difference:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Do certain events make calls to repaint redundant? (Part 2)
 
Similar Threads
enabling the scrollbar when components are dynamically added in jpanel
Scrollbars
Problem with custom painting and multiple JPanel
JLabel ..does it accept HTML ?
How to Add Graphics to Jpanel