how to determine what item is highlighted in a comboBox?

hi,

suppose you have a JComboBox with the popup visible, the list exposed.

I want to, during a keyPressed event, be able to determine if the mouse is

hovering over (and, therefore, highlighting) one of the items in my JComboBox

list. If so, I want to get the index for that item.

Probably not as easy as it sounds, right? Any ideas?

thanks!

[386 byte] By [pnandrusa] at [2007-11-26 16:21:11]
# 1
I would start by researching MouseListeners: http://java.sun.com/docs/books/tutorial/uiswing/events/mouselistener.htmlLess than a second in Google.^^Sean
DataVirtuea at 2007-7-8 22:44:49 > top of Java-index,Desktop,Core GUI APIs...
# 2

> Probably not as easy as it sounds, right? Any ideas?

No, its not. While it would be nice to be able to just register a MouseListener with the JComboBox or something, it won't work correctly. What's more, you don't have access to the popup menu unless you start making assumptions about the L&F implementation. Many people have run into this (or related) problem. See here: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4144505

My solution: implement my own JComboBox. This effectively breaks the multiple L&F support. There are probably other solutions out there.

Jasprea at 2007-7-8 22:44:49 > top of Java-index,Desktop,Core GUI APIs...