How do I deal with focus events on custom components?

D

DeMarcus

Hi,

I have created a custom MyComboBox component that extends
from JPanel. From there I build up my combobox with a couple
of standard swing components.

To me (as I want it) the MyComboBox has focus as long as any
of the components within has focus.

My question is; what's the best way to detect a lost focus
event on the whole MyComboBox?

Thanks
Daniel
 
J

John C. Bollinger

DeMarcus said:
Hi,

I have created a custom MyComboBox component that extends
from JPanel. From there I build up my combobox with a couple
of standard swing components.

To me (as I want it) the MyComboBox has focus as long as any
of the components within has focus.

But that conflicts with the way AWT / Swing define the focus. Only one
component has the focus at a time. You can make your custom component
simulate gaining / losing the focus, however, by having it listen for
the internal components' focus events and fire its own focus events in
response. This ought to work fairly well as long as you keep the
internal components well encapsulated, but it has potential to cause
trouble if the internal components are exposed.
My question is; what's the best way to detect a lost focus
event on the whole MyComboBox?

See above.


John Bollinger
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top