This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Swing performance  RSS feed

 
Sathish Babu Adluru Subas
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Why is GUI(Swing,AWT) in Java much much slower than any other GUIs? Why is this prob. not yet been rectified so far?
 
paul wheaton
Trailboss
Posts: 22521
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a pretty massive applet and it's speed is so fast that I can't tell the difference. Of course, I'm running a P3.
The AWT is a layer of java on top of the underlying operating system. Even Swing uses some of the AWT, so there is no way around this. But, have you ever tried to develop directly to the windows API? Plus, while there is a performance hit, the up side is that now your code will run on any O/S with a vm. I've tried my code on a few flavors of windows and unix and it all worked exactly the same. Pretty cool.
 
Sathish Babu Adluru Subas
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But,already creating a complex GUI app is very tedious and if iam going to develop it directly using windows API,its gonna become an even more tedious job. isn't it,Paul?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Paul's point is that yes, developing directly for Windows would be very tedious, and it's much more fun and easy in Java. He's not recommending the Windows API option.
As for "why has this prob. not been rectified so far?" - it has improved considerably with each new release, I think, though there's still room for improvement. But like Paul, I've got a large GUI application that runs quite fast enough for me. The slower machine that I run it on has an AMD K6 266MHz processor with 64 Mb. What sort of environment are you using?
One thing you may want to look into - often when the GUI seems slow, it's because the event handler for an AWT Component has called a method which is time-consuming to execute. It's not the GUI itself that's slow, but rather whatever code you wrote that you are running. This can be fixed by having the event handler start a new thread to execute whetever task you want it to, so that the handler can return quickly and the AWT event processing thread is again free to handle whatever other events come up. Multithreading has its own set of issues you'll need to study if you haven't yet, but it's very useful for this sort of thing.
 
Sathish Babu Adluru Subas
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx friends.but please suggest some sites/info about directly developing for windows or some examples that would do a world of good.
moreover,are there any dos/don'ts in Swing/AWT which influences the performance/efficiency of same. and then,if my class is very big(say some 400 lines of code),hows it going to affect the performance?
thanx once again...
 
paul wheaton
Trailboss
Posts: 22521
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I learned the hard way: don't develop to the Windows API, use Java instead.
As for performance stuff, I suggest you ask that question in the performance forum - you will get a lot more feedback there.
As with any language, as you gain experience, you will learn the small things that take up time.
You might consider doing the "cattle drive". In that, you do eight assignments and I go line by line telling you of better ways to work you code for both speed and readability.
If you are going to post some code and ask for optimization tips, I suggest you do no more than 20 lines. I know that whenever I see anything more than 20 lines I think: if this guy wants me to read this much stuff, he can pay me. For a few lines, I don't mind helping a fellow programmer out.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!