JComboBox - add listener to the button press

  • Follow


Hi all,

I added an action listener to the button of the JComboBox.
This worked fine, until I changed the UI of the JComboBox to be
MotifComboBoxUI.
Since then the button is null and I couldn't find how to add a listener
to the operation of pressing the button of the JComboBox.
Does anyone have any idea?

Thanks.

0
Reply katz.merav (8) 12/17/2006 1:49:12 PM

mera wrote:
....
> I added an action listener to the button of the JComboBox.
> This worked fine, until I changed the UI of the JComboBox to be
> MotifComboBoxUI.
> Since then the button is null and I couldn't find how to add a listener
> to the operation of pressing the button of the JComboBox.

Huhh?

> Does anyone have any idea?

Post code that demonstrates the problem.
<http://www.physci.org/codes/sscce>

Andrew T.

0
Reply Andrew 12/17/2006 2:11:22 PM


Maybe I didn't make myself clear ...
I want that pressing the arrow button will do more than just open the
popup, but some other operations as well ...

Andrew Thompson wrote:
> mera wrote:
> ...
> > I added an action listener to the button of the JComboBox.
> > This worked fine, until I changed the UI of the JComboBox to be
> > MotifComboBoxUI.
> > Since then the button is null and I couldn't find how to add a listener
> > to the operation of pressing the button of the JComboBox.
>
> Huhh?
>
> > Does anyone have any idea?
>
> Post code that demonstrates the problem.
> <http://www.physci.org/codes/sscce>
> 
> Andrew T.

0
Reply mera 12/17/2006 2:37:14 PM

mera wrote:
> 
> I added an action listener to the button of the JComboBox.
> This worked fine, until I changed the UI of the JComboBox to be
> MotifComboBoxUI.
> Since then the button is null and I couldn't find how to add a listener
> to the operation of pressing the button of the JComboBox.
> Does anyone have any idea?

Trying to do this sort of thing is bound to be PL&F specific. You can 
add a PopupMenuListener to listen for any action (click, F4, Alt-Down, 
etc) that opens a popup menu. However, even the API docs for that 
mention that a combo box is not necessarily implemented with a popup menu.

http://java.sun.com/javase/6/docs/api/javax/swing/JComboBox.html#addPopupMenuListener(javax.swing.event.PopupMenuListener)

Tom Hawtin
0
Reply Thomas 12/17/2006 2:54:04 PM

mera wrote:

Please refrain from top-posting.

> Maybe I didn't make myself clear ...

Sure didn't - not to me anyway.

> I want ....

Yeah, yeah..  Like I said earlier.
"Let the code do the talking"

That URL again..
> > Post code that demonstrates the problem.
> > <http://www.physci.org/codes/sscce>

Andrew T.

0
Reply Andrew 12/17/2006 2:58:29 PM

4 Replies
183 Views

(page loaded in 0.093 seconds)

Similiar Articles:












7/12/2012 10:55:41 AM


Reply: