Skip to main content

How to make swing application work faster?

8 replies [Last post]
meek
Offline
Joined: 2005-10-13

Hi,

I am working on swing based application at front end, the application i have made is much slower compare to an application made in .NET. I have used SWING components for the front end.

I want to know for a nice article to make the swing application work faster. I have tried to search all the way on internet but unable to find a nice article. Can you people help me out.

I don't want to use any third party api for faster perfomance (JGoodies, JIDE, etc).

Please help me out.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
meek
Offline
Joined: 2005-10-13

thanks guys for your reply. It may be some EDT problem. I'll definitely read the tutorials you pointed at.

Since you asked, what problem i actually facing. When a screen is about to display (which have, panels, buttons, lists) it remain blank at the start and display after a while. Similarly if i swich from one tab to another tab, it initially displays nothing and then displays gradually.

nickynarak
Offline
Joined: 2006-11-16

answer have in JFC swing tutorial second edition.

vivpr
Offline
Joined: 2005-02-04

Meek,

The first step that you should try out is to profile your application.. that way, you'll get a better idea of exactly where the bottlenecks are. The problem need not necessarily be related to Swing - it could be related to the choice of a poorly performing algorithm, for instance.

Regards,
vivpr

evickroy
Offline
Joined: 2004-07-23

Also, check your log for an exception. Sometimes an exception can short circuit painting if it isn't handled properly.

Erik

chris_e_brown
Offline
Joined: 2004-09-14

Third-party APIs aren't really the solution. Swing is usually fast, I suspect you're having difficulty in using the Event-Dispatching Thread correctly (if you don't know what I'm talking about, then that's probably the case...).

I've almost finished a big blog entry on this subject but I'm in the middle of moving house right now so don't have time to finish it off. You should still be able to find out about solutions for better performance by searching for information on the "Event-Dispatching Thread" (often referred to as the EDT), "SwingWorker", or "Foxtrot". It's to do with multi-threading, but it's best to understand what's going on.

Can you describe in more detail the specific problems you're observing? E.g.: slow refresh, buttons remaining "pushed in", slow startup, ...?

- Chris

coxcu
Offline
Joined: 2003-06-11

A Swing application feeling slow is almost definitely an EDT violation.

The best place to start learning about the EDT is Ben Galbraith's presentation on Java Lobby.
http://www.javalobby.org/members-only/eps/galbraith-swing-2/index.html?s...

Here's a discussion that you might be interested in.
http://weblogs.java.net/blog/alexfromsun/archive/2006/02/debugging_swing...

I would love to be able to point you to the JSR-296 reference implementation, since that will have tools to help prevent EDT problems. Sadly, it is not available, yet.

bellbux
Offline
Joined: 2006-09-08

On this subject I have a query. The single thread rule says anything that 'depends on the state of the GUI' must be done in the EDT. For the Swing components that are backed by a model - is it safe to call the get methods e.g. getText().
Presumably this get call depends on the state of the model not the GUI? cheers

tackline
Offline
Joined: 2003-06-19

Everything threaded is prohibited unless explicitly excepted. Actually, even the stuff claiming to be thread-safe tends to be unsafe (either because it is really thread-unsafe or it uses invokeLater in some half-arsed state). I suggest if you are going to access anything Swing, you do it on the EDT.