swing programming: alternatives for gridbaglayout and swing threading

there are two pretty cool presentations on javalobby.org about (better) swing programming. one about threads and swing, the other about look and feels and layout managers.

most interesting:

1. threading: keep your listener methods leight weight, because these block your gui if they take too long to complete. if you have to do some larger work in a lister method, spawn a new thread. the best way to do this is using foxtrot:


public void actionPerformed(ActionEvent e) {
statusLabel.setText("stand by");

try
{
text = (String)Worker.post(new Task()
{
public Object run() throws Exception
{
// do lots of stuff that takes a long time
}
});
}
catch (Exception x) ...

statusLabel.setText("done");

somethingElse();
}

the actually cool thing about foxtrot is that it works synchronously: the current thread waits until the worker has finished his task - without freezing swing.

2. gridbaglayout: jgoodies forms is an alternative to the GridbagLayout that is much easier to use

Tags:

Leave a Reply