It's not a secret anymore!*
The moose likes Performance and the fly likes poor gui performance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "poor gui performance" Watch "poor gui performance" New topic
Author

poor gui performance

Ivan Kesic
Ranch Hand

Joined: Feb 05, 2009
Posts: 68
Hello

I'm making software for my customer where he can store information in database. GUI has panels on every form, where a picture is loaded in constructor from a path stored in database. So, i am having a problem, even though the picture loading process takes like 1 sec of time, after that the whole time everything is working slower. Writing in text box, selecting from combo box, everything has a lag, lets say about 0.5 sec. I have no idea why is this happening. There is no loading in background after initial drawing of panel, nothing that will slow down program. Any ideas?

Thank you
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12825
    
    5
I would certainly take a look at memory use, perhaps the operating system is doing a lot of memory paging due to the amount of space used by graphic elements.

Bill
Ivan Kesic
Ranch Hand

Joined: Feb 05, 2009
Posts: 68
Well when i look at memory used at the time when program is working, in stays at like 65% the whole time. Is there maybe something wrong with panels. Panels are used as backgrounds on every form. And they are using small pictures,about 3 mb. I just cant figure out why is it slow when the image is already loaded and drawn... And it is only 1 graphic element on every form ( few buttons here and there but nothing special).
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18911
    
    8

There's also the possibility that your code is doing something bad.

(Do you really consider 3 megabytes to be a "small" picture? That might be part of your problem too.)
Ivan Kesic
Ranch Hand

Joined: Feb 05, 2009
Posts: 68
I made pictures to be 100 kb, still same thing. Ill see code, but there are no threads, no loops, nothing that can take memory...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18911
    
    8

Don't focus too much when you are looking for unknown code problems. Just looking for code which might use memory isn't a good strategy. For all we know you're doing too much in the paintComponent method, just for example.
Ivan Kesic
Ranch Hand

Joined: Feb 05, 2009
Posts: 68
Here is the code which i use to paint picture on background. When that happens, nothing is done with this code further. But all elements (few buttons, or combo boxes) are on this panel.


Also, i looked at performance of CPU and memory usage, and everything is fine. Im not sure that this have anything to do with that.
Ivan Kesic
Ranch Hand

Joined: Feb 05, 2009
Posts: 68
Any ideas? Maybe when i make jar itll work, i have no other idea...
Andrey Kozhanov
Ranch Hand

Joined: Mar 12, 2010
Posts: 79
Your problem is on line 90: g2.drawRenderedImage(m_ScaledImage, at);

Timing shows that it took about 0.5 seconds to complete. paintComponent method is triggered every time you do something in application window, that's why you have 0.5 seconds delay for every operation. So looks like you should either remove background picture or have a set of different size pictures or use some other technology for drawing. Maybe you would find something useful here: http://fivedots.coe.psu.ac.th/~ad/jg/ch045/index.html
Ivan Kesic
Ranch Hand

Joined: Feb 05, 2009
Posts: 68
Hmmm, i don't know any other technology for drawing. Is there any other easy way of stopping application to call paintComponent of jpanel, becouse i can't remove background picture, it must be shown on that panel?! And picture cant be smaller...
Only thing i found is that maybe im able to do something with Class SwingWorker, to create a thread for painting picture...but i just cant make it to work...
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12825
    
    5
It has been quite a long while since I did this sort of thing, but you appear to be rescaling the original every single time the component is drawn.

Why not keep a copy of the scaled image and use it if the component has not been resized?

Bill
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: poor gui performance