Thread View: borland.public.jbuilder.java.swing
4 messages
4 total messages
Started by Steve
Thu, 25 Dec 2003 00:33
GUI Responsiveness Problem
Author: Steve
Date: Thu, 25 Dec 2003 00:33
Date: Thu, 25 Dec 2003 00:33
25 lines
2354 bytes
2354 bytes
Imagine a GUI control that starts a long-running process from its action event. Since the event handler executes on the event-handling thread, the GUI is frozen while the process completes. Often this is exactly what we want (e.g., refreshing a query; there's nothing for the user to do until the refresh is complete). JButton handles this nicely by depressing and changing the cursor _before_ the action event handler is called so that the user knows the application isn't frozen. But JComboBox leaves its picklist extended and appears frozen to the user until the event handler exits. What I'd like to be able to do is for the JComboBox to get ahold of itself, but still block on the event-handling thread after that. Any ideas? I came up with a really hideous hack that I'm not happy with: In the action event handler, create a SwingWorker with an empty construct() method and the long-running process called from the finished() method (forcing it on to the event-dispatching thread). The start() method is called just before the event handler exits. This gives the GUI enough time to retract the picklist. However this is a kludge because it's timing dependent. It also doesn't work if you put any other GUI code in the event handler (e.g., setting the wait cursor) unless you add a delay timer to the construct method. There's gotta be an easier way to do something so basic. Any ideas greatly appreciated. Thx. -Steve
Re: GUI Responsiveness Problem
Author: pNichols
Date: Sat, 27 Dec 2003 03:48
Date: Sat, 27 Dec 2003 03:48
36 lines
2773 bytes
2773 bytes
Steve wrote: > Imagine a GUI control that starts a long-running process from its action > event. Since the event handler executes on the event-handling thread, the > GUI is frozen while the process completes. Often this is exactly what we > want (e.g., refreshing a query; there's nothing for the user to do until > the refresh is complete). JButton handles this nicely by depressing and > changing the cursor _before_ the action event handler is called so that > the user knows the application isn't frozen. But JComboBox leaves its > picklist extended and appears frozen to the user until the event handler > exits. > > What I'd like to be able to do is for the JComboBox to get ahold of > itself, but still block on the event-handling thread after that. Any > ideas? > > I came up with a really hideous hack that I'm not happy with: In the > action event handler, create a SwingWorker with an empty construct() > method and the long-running process called from the finished() method > (forcing it on to the event-dispatching thread). The start() method is > called just before the event handler exits. This gives the GUI enough time > to retract the picklist. However this is a kludge because it's timing > dependent. It also doesn't work if you put any other GUI code in the event > handler (e.g., setting the wait cursor) unless you add a delay timer to > the construct method. There's gotta be an easier way to do something so > basic. > > Any ideas greatly appreciated. Thx. > > -Steve there was a good article this month In Java Developer's Journal about Swing and Listener events performance probems that you might want to take a look at. I think it could address some of your issues. www.sys-con.com Look at the bottom article, Swing,Threads, and events
Re: GUI Responsiveness Problem
Author: Steve
Date: Sat, 27 Dec 2003 21:51
Date: Sat, 27 Dec 2003 21:51
14 lines
1793 bytes
1793 bytes
"pNichols" <paul@computer-logic.net> wrote in message news:3fecff09$1@newsgroups.borland.com... > there was a good article this month In Java Developer's Journal about Swing > and Listener events performance probems that you might want to take a look > at. I think it could address some of your issues. Thanks for the tip. It covers about the same ground as the Sun tutorial, albeit with more example code. It did nudge me to look at the source for SwingWorker, though. Since the finished() routine is run by invokeLater, it should be attached to the end of the queue. Since this doesn't always have the effect I intended, it strengthens my suspicion that this was just lack of forsight in the way that JComboBox was written (i.e., the list should be retracted before it calls the action event handler).
Re: GUI Responsiveness Problem
Author: pNichols
Date: Mon, 29 Dec 2003 07:58
Date: Mon, 29 Dec 2003 07:58
23 lines
2236 bytes
2236 bytes
Steve wrote: > "pNichols" <paul@computer-logic.net> wrote in message > news:3fecff09$1@newsgroups.borland.com... >> there was a good article this month In Java Developer's Journal about > Swing >> and Listener events performance probems that you might want to take a >> look at. I think it could address some of your issues. > > Thanks for the tip. It covers about the same ground as the Sun tutorial, > albeit with more example code. It did nudge me to look at the source for > SwingWorker, though. Since the finished() routine is run by invokeLater, > it should be attached to the end of the queue. Since this doesn't always > have the effect I intended, it strengthens my suspicion that this was just > lack of forsight in the way that JComboBox was written (i.e., the list > should be retracted before it calls the action event handler). There are a myriad of problems with Listeners and Event classes in Java Swing. I constantly monitor my programs to see how many iterations they make through an ActionEvent or WindowListener which will fire not only on these events but any subsequent events within the same inner class. I think Javasoft DEFINITELY needs to revisit the way they implement these Listener classes.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads