🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.java.programmer
3 messages
3 total messages Started by Stan Reinis Fri, 02 Jul 1999 00:00
ActionEvent on a JComboBox problem
#414
Author: Stan Reinis
Date: Fri, 02 Jul 1999 00:00
21 lines
1527 bytes
We have a JComboBox on a JPanel.

We need to call a method when the user changes the selected item
in the combobox.  We have been using ActionEventListener to
accomplish this.  However, if the combobox already has a value
assigned to it when the panel is opened, we do not want to call
this event.  Unfortunately (for us), an ActionEvent is fired when
we programatically set the value in the combobox.

To overcome this, we added a boolean that is set to false just before
we programatically change the value in the combobox.  Then we change
it back.

Occasionally it happens that the Action is processed before the boolean
changes.  Apparently Actions are run on a different thread than the
main execution, which causes a race condition.

What can we do here?

Stan
Terren Corporation
Re: ActionEvent on a JComboBox problem
#415
Author: Sandy Mustard
Date: Fri, 02 Jul 1999 00:00
32 lines
1892 bytes
A possible fix for this would be to remove the listener when
you programatically set the value and then add it again. This way
you don't need the boolean.

On panel open, if you set the value before adding the listener, it
won't be called.

Sandy Mustard

Stan Reinis wrote:
> 
> We have a JComboBox on a JPanel.
> 
> We need to call a method when the user changes the selected item
> in the combobox.  We have been using ActionEventListener to
> accomplish this.  However, if the combobox already has a value
> assigned to it when the panel is opened, we do not want to call
> this event.  Unfortunately (for us), an ActionEvent is fired when
> we programatically set the value in the combobox.
> 
> To overcome this, we added a boolean that is set to false just before
> we programatically change the value in the combobox.  Then we change
> it back.
> 
> Occasionally it happens that the Action is processed before the boolean
> changes.  Apparently Actions are run on a different thread than the
> main execution, which causes a race condition.
> 
> What can we do here?
> 
> Stan
> Terren Corporation
Re: ActionEvent on a JComboBox problem
#416
Author: tech
Date: Fri, 02 Jul 1999 00:00
39 lines
2219 bytes
This is interesting. I always thought that the ActionEvent is not called
when programatically changing the seletion. I thought that only
SelectionChanged events are fired.  In fact I had to use ActionEvent
instead of selection event to avoid a loop (I was updating the
gui). But then I may be confusing this with awt List/Choice/Combobox

-sandip


In article <377CF6DE.3049A54A@terren.com>,
  Stan Reinis <stan@terren.com> wrote:
> We have a JComboBox on a JPanel.
>
> We need to call a method when the user changes the selected item
> in the combobox.  We have been using ActionEventListener to
> accomplish this.  However, if the combobox already has a value
> assigned to it when the panel is opened, we do not want to call
> this event.  Unfortunately (for us), an ActionEvent is fired when
> we programatically set the value in the combobox.
>
> To overcome this, we added a boolean that is set to false just before
> we programatically change the value in the combobox.  Then we change
> it back.
>
> Occasionally it happens that the Action is processed before the
boolean
> changes.  Apparently Actions are run on a different thread than the
> main execution, which causes a race condition.
>
> What can we do here?
>
> Stan
> Terren Corporation
>
>


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
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