Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

poor gui performance

 
Ivan Kesic
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any ideas? Maybe when i make jar itll work, i have no other idea...
 
Andrey Kozhanov
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic