PopupMenuListener event on JComboBox fires multiple times per selection

// webAddressBox IS OF TYPE javax.swing.JComboBox

webAddressBox.addPopupMenuListener(new PopupMenuAdapter(){

/** @uses {@link com.ppowell.tools.ObjectTools.SimpleBrowser.Surf} */

final Surf surf =new Surf(webAddressBox.getSelectedItem().toString());

/**

* Perform {@link #surf} processing

* @param evt {@link javax.swing.event.PopupMenuEvent}

*/

publicvoid popupMenuWillBecomeInvisible(PopupMenuEvent evt){

System.out.println("you selected:");

surf.doURLProcessing();

}

});

/*

* PopupMenuAdapter.java

*

* Created on February 16, 2007, 11:53 AM

*

* To change this template, choose Tools | Template Manager

* and open the template in the editor.

*/

package com.ppowell.tools.ObjectTools.SwingTools;

import javax.swing.event.PopupMenuEvent;

import javax.swing.event.PopupMenuListener;

/**

* Will allow for greater flexibility by implementing {@link javax.swing.event.PopupMenuListener}

* @author Phil Powell

* @version JDK 1.6.0

*/

publicabstractclass PopupMenuAdapterimplements PopupMenuListener{

/** Creates a new instance of PopupMenuAdapter */

public PopupMenuAdapter(){}

/**

* Overrides {@link javax.swing.event.PopupMenuListener} method popupMenuCanceled

* @param evt {@link javax.swing.event.PopupMenuEvent}

*/

publicvoid popupMenuCanceled(PopupMenuEvent evt){}

/**

* Overrides {@link javax.swing.event.PopupMenuListener} method popupMenuWillBecomeInvisible

* @param evt {@link javax.swing.event.PopupMenuEvent}

*/

publicvoid popupMenuWillBecomeInvisible(PopupMenuEvent evt){}

/**

* Overrides {@link javax.swing.event.PopupMenuListener} method popupMenuWillBecomeVisible

* @param evt {@link javax.swing.event.PopupMenuEvent}

*/

publicvoid popupMenuWillBecomeVisible(PopupMenuEvent evt){}

}

This code is supposed to handle a single selection from a JComboBox webAddressBox. The front-end functionality of this code blocks works just fine to the user, however, upon viewing the "behind the scenes action", I noticed that the overriden popupMenuWillBecomeInvisible() method within the anonymous inner class instance of PopupAdapter is being called 2 times upon the first time you select something from webAddressBox, 4 times the next time you select something, 8 times the next time, and so on..

Obviously this is a tremendous waste of resources to have it call that many times exponentially - it should only call once each time you select something from webAddressBox, but I can't figure out how to get that to happen.

What suggestions might you have to accomplish this? I already have an ActionListener that runs separately from PopupMenuAdapter that handles the user either clicking a JButton or hitting ENTER - this works just fine.

Thanx

Phil

[4290 byte] By [ppowell777a] at [2007-11-26 18:43:26]
# 1
> is being called 2 times upon the first time you select something from > webAddressBox, 4 times the next time you select something, 8 times the next time, and so on..Then you are adding the listener to the component multiple times.
camickra at 2007-7-9 6:17:21 > top of Java-index,Desktop,Core GUI APIs...
# 2

> > is being called 2 times upon the first time you

> select something from

> > webAddressBox, 4 times the next time you select

> something, 8 times the next time, and so on..

>

> Then you are adding the listener to the component

> multiple times.

WTO *sigh*.. thanx! :)

ppowell777a at 2007-7-9 6:17:21 > top of Java-index,Desktop,Core GUI APIs...