🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.lenguajes.java
Article #25964

Re: Distinguir entre eventos por programa y por usuario en JComboBox y otros componentes

#25964
From: Ismael
Date: Thu, 18 Feb 1999 00:00
158 lines
6156 bytes
Yo mismo me respondo:

He encontrado informacion sobre como hacerlo y aunque no es que sea muy
elegante funciona.
Espero que os sirva de ayuda.

Alla va la info:

DukeDollars Question
                 Newsgroup: jfc
                 Submitter: FergusG
                 Question:
Stopping_JComboBox.removeAllItems()_generating_actionEvents
                 Date:  Mon Jul 13 05:20:04 PDT 1998

                 Question number: 61

                 ** This question is still open **
                 JDC-notify: true

                 I have a series of event-linked JComboBoxes, the elements
of which are determined by the combo one up the tree.
                 When I select one combo, it calls removeAllItems() on the
child combo, and then addItem() multiple times.

                 My problem is that removeAllItems generates actionEvents,
which cannot be disabled with setEnabled(false),
                 so I get lots of extra events generated, which then
propagate "invalid" events down the tree.

                 Any suggestions?

                 Thanks, Fergus

                 JRE/JDK 1.1.6 on NT 4.0



                 Answers
                 =======

                 ** From: rwiditz:

                 Replied: Mon Jul 13 10:10:57 PDT 1998

                 Call removeActionListener() for as long as necessary then
addActionListener() once you achieve
                 your desired effect...  This should "disable" undesirable
event actions.


                 ** From: Denka_B:

                 Replied: Sat Jul 18 15:04:00 PDT 1998

                 Hi!

                 Try to create new JComboBox and to dispose old by settting

                 oldCombo = nul;
                 If you need somethig of old combo, do appropriate
assignments before disposing it.

                 Kinda hack?

                 ** From: jferrando:

                 Replied: Wed Aug 12 23:50:19 PDT 1998

                 Hi.

                 I had a similar problem and tryed the solution proposed in
the first answer. I seems that it should
                 work, but for some reason, the program is faster
reinstaling the control as a listener than the
                 messages traveling, so it gets them anyway (in my case, I
insist).
                 My suggestion: Try to get from the aparamenter you receive
the kind of event that fired the
                 call and so decide if you have to ignore it or not. You
could also define a state machine to help
                 you discren between types of events.

                 Hope this helps.

                 Juan Alvarez Ferrando.

                 ** From: Greg_B:

                 Replied: Wed Nov 04 11:19:10 PST 1998

                 I do this all the time in our code.  I want to dynamically
change the entries is a list box or combo box,
                 but I don't want the addition or removal of those items to
fire an action.  My solution was simple:
                 wrap the action listener with an if-then like this

                 streetList.addActionListener( new ActionListener() {
                    public void actionPerformed( ActionEvent e ) {
                       if(isStreetActionListenerOn == true) {
                           streetAction();
                       }
                 } } );

                 Then, let's say I want to clear a selection but not fire
the action I would do this.
                 isStreetActionListenerOn = false;
                 streetList.clearSelection();
                 isStreetActionListenerOn = true;

                 That way I avoid any the the problems in the previous
answer where the actions are not being removed
                 fast enough.


                 "THE INFORMATION PROVIDED IN THE JAVA DEVELOPER'S
CONNECTION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS

                 OR IMPLIED, INCLUDING WITHOUT LIMITATION THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR, AND NON-INFRINGEMENT.

                 THIS INFORMATION IS PROVIDED AT NO CHARGE. BY USE OF THE
INFORMATION YOU AGREE THAT NEITHER SUN MICROSYSTEMS, INC. NOR ITS
                 LICENSORS WILL BE LIABLE FOR ANY DAMAGES WHATSOEVER
INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS
                 PROFITS OR SPECIAL DAMAGES, EVEN IF SUN OR ITS LICENSORS
HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT
                 ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR
CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT
                 APPLY.


Ismael wrote:

> Hola a todos.
>
> Me gustaria saber si hay alguna forma de distinguir cuando en un
> JComboBox se cambia el item seleccionado por programa y cuando es
> cambiado por el usuario.
>
> Tengo una aplicacion que accede a la BD, por lo tanto cada vez que
> muestro un registro cambio el item en el JComboBox, hasta aqui ningun
> problema.
>
> Yo lo que deseo es que cuando el usuario cambia el contenido del
> combobox se ejecute un metodo ,que se encargua de realizar una serie de
> acciones para mantener la consistencia de la BD, pero que no se ejecute
> cuando sea el programa el que esta cambiando el item seleccionado del
> combobox.
>
> Igual que con el combobox me pasa con un JSlider.
>
> En resumen:
>
> �Como diferenciar si un objeto es generado por programa de un evento
> generado por el usuario?
>
> Muchas gracias
Technical Details
Message-ID: <36CBF7D8.4933BC0@tissat.es>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <36CA7AED.BBC1DAC3@tissat.es>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 1116f3,9aed8a431f222d5c
X-Google-Attributes: gid1116f3,public
From: Ismael <iblesa@tissat.es>
Subject: Re: Distinguir entre eventos por programa y por usuario en JComboBox y  otros componentes
Date: 1999/02/18
Message-ID: <36CBF7D8.4933BC0@tissat.es>
X-Deja-AN: 445658481
Content-Transfer-Encoding: 8bit
References: <36CA7AED.BBC1DAC3@tissat.es>
X-Accept-Language: en
Content-Type: text/plain; charset=iso-8859-1
Organization: Telefonica Transmision de Datos
Mime-Version: 1.0
Newsgroups: es.comp.lenguajes.java