Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

SWING Repaint question  RSS feed

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know why SWING repaints ALL THE TIME?? I know that at the adapter level there are more efficient ways to handle how graphics get displayed on the screen and the repainting a component just because my mouse moved over it is not nessecary if programmed correctly.
Anyone know if SWING utalizes overlay buffers anywhere?
Thanks.
 
Ashish Mahajan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gregg,
It will be interesting to study this. Since i don;t know about this, in this case i'll better lurk.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In dealing with OpenGL and GLUT, I have noticed that Repainting and Redrawing are huge overheads. And that utalizing double buffering and especially overlay buffering, you can reduce the amount of repainting. Of course, this is all done at the adapter level. So maybe the VM just can't handle that? I don't know. Maybe this is just another one of those "suggest it to sun" and hope for the best?
 
Ashish Mahajan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Gregg,
Am not a old guy in programming. Still learning the ABC's of computers. So such high fundas r well over my head. But still i'll try to look for them and if i find any i'll post them.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the best examples of bad repainting I can think of is with JTree. And I learned this the hardway.
I was creating a ToolTip for my JTree nodes and the info was being pulled from the Database. Because of my horrible design, but more importantly, because of the repaint method, my database was being called and my tootip was being built for every visible node everytime my mouse moved.
I fixed my design so that the database is not getting hit, nor am I creating the tooltip in the TreeModel anymore. But the fact remains that everytime I move my mouse, even 1 pixal, over the JTree repaint get's called for the entire JTree. That just seems rediculous.
So that kind of prompted this investigation into SWING repaint.
 
Ashish Mahajan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gregg,
Am assuming that u have turned on the tool tip for ur tree. By default it's not turned on.
Gregg, have u considered overriding getToolTipText(MouseEvent) method of JTree. If not Please see javadoc of JTree for this method.
A possible code might be :-
public String getToolTipText(MouseEvent me)
{
int row = getRowForLocation(me.getX(), me.getY());
if(row == - 1){
return super.getToolTipText(me);
}

DefaultMutableTreeNode node = (DefaultMutableTreeNode) getPathForRow(row).getLastPathComponent();
// do whatever with it's child nodes or with it's user object


return toolTip;
}
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the suggestion. The problem is not my ToolTip. In fact, I don't really have a problem.
I was only mentioning that because it prompted my initial question/comment in this thread.
I could care less about the Tooltip. The fact is that everytime I move my mouse across a JTree, that JTree repaints itself. That, to me, is just bad design. That is why I wanted to find out more on the reasoning behind Repainting of components in SWING.
Thanks.
 
Ashish Mahajan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gregg,
It will be really interesting to investigate.
BTW i liked text component's dedsign. Only the current line, the line above it and the line below it r painted and not all.
Let's C what oter's say.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used this code below to test out how JTree is doing it's painting... it looks like usually the repaint is doing OK, but one case that looks kinda bad is how it gets done during selection... it looks like all nodes in the 'family' ( all nodes directly under the same parent node ) get repainted for the node being selected and the node that was previously selected... not sure why this is being done...

 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you all talking about 1.4 or some older versions?

Implementation Note: This class overrides validate, revalidate, repaint, and firePropertyChange solely to improve performance.
If not overridden, these frequently called methods would execute code paths that are unnecessary for the default tree cell renderer. If you write your own renderer, take care to weigh the benefits and drawbacks of overriding these methods.

(quoted from API 1.4.1, TreeCellRenderer)
Chantal
[ March 04, 2003: Message edited by: Chantal Ackermann ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using 1.4.1_02. Your quote begins with "..This class..."
What class?
Can you give me a link?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just caught your Edit.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no doubt that performance issues have been dealt with in newer versions of the JDK.
I also have no doubt that GUI Components in SWING are still being repainted, improved performance or not.
So back to my original question, why does SWING have to repaint so much? Is it something inherent in Windows Programming in general? But then what about Linux X11? It is still going to repaint all the time?
Just looking for some insight on the reason behind so much repainting.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm running JDK1.4.1_01 on a Windows 2000 box here at work...

Running the RepaintTree code I supplied above doesn't show an overabundance of repaint calls, except in the selection/deselection bit I mentioned above...

When you talk about repainting "all the time" what is going on? I don't get a repaint call just from moving my mouse over the tree... perhaps it had more to do with the ToolTip code???
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nathan Pruett:
I'm running JDK1.4.1_01 on a Windows 2000 box here at work...

Running the RepaintTree code I supplied above doesn't show an overabundance of repaint calls, except in the selection/deselection bit I mentioned above...

When you talk about repainting "all the time" what is going on? I don't get a repaint call just from moving my mouse over the tree... perhaps it had more to do with the ToolTip code???


Well, I may be enfering too much from another observation.
When I move my mouse over a JTree node, the Renderer gets called. I had put a println statement in my renderer and everytime I moved my mouse, even just a pixal, it printed out on the screen. So I assumed that the repaint method was actually causing the renderer to be called again. I guess I am probably wrong. Could you clareify/verify this?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Run the RepaintTree code I posted above...

Simply moving the mouse over the nodes is not causing a repaint...
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I edited RepaintTree above to provide tooltips, and this caused quite a few more repaints....

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!