Skip to main content

Focus lost on a Panel

2 replies [Last post]
hsantos
Offline
Joined: 2005-04-07

Hi
I have 2 JPanels, each of them containing some JTextFields, JComboBoxes where user inputs data.
I'd like to perform some validation when user leaves panel1 and enters panel2, but I don't know how to catch that event.
Adding a FocusListener to each panel doesn't seem to work ...

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mgrev
Offline
Joined: 2003-08-12

Adding the fucus listener to the JTextFields/Combos is one approach that works for sure.

As a more flexible solution you can subclass the JPanels and intercept (override) jPanel.add(Component c) and add the listener to 'c' there.

You can also subclass the JTextFields and JComboBoxes to make them validate thier content everytime the focus is lost, but that is may not be what you want, depending on your context.

hsantos
Offline
Joined: 2005-04-07

Thanks,
I added a FocusListener to all of my components and it just works fine :)