Re: How to detect focus lost on a JPanel
- From: Ian Wilson <scobloke2@xxxxxxxxxxxxx>
- Date: Tue, 17 Apr 2007 10:01:12 +0100
clearlight@xxxxxxxxx wrote:
Hi,
I am new to Java. As a basic learning project, I started writing a no-
frill small general ledger application.
The basic design is a Frame containing a menu and a JTabbedPanel. When
a menu option is selected, a component derived from JPanel containing
the graphical interface for the data entry of the selected option is
created, added to the JTabbedPane component and the corresponding Tab
is selected.
Inside any of this panels, there are JTextFields that have to be
validated (via InputVerifiers).
Now, if focus is inside any of this JTextFields, and I select a new
option from the frame's menu, validation shouldn't be fired.
So far, I have tried to add a FocusListener to the JPanel descendents,
but it doesn't work as I expected: JPanel fires a focusLost event when
focus enters a JTextField contained within the panel itself, and fires
nothing when a menu option is selected.
If I establish a dependency between the main JFrame and the contained
JPanel derivates, I might perhaps design a sort of bidirectional
notification protocol, but I would like to avoid any dependence that
can be avoided.
So, is there a standard event that lets me know when the focus leaves
a JPanel (FocusListener doesn't work, because -at least in my
configuration: NetBeans 5.5, JDK 1.6, WinXP- it fires when a control
within the panel gains focus)?
I had a similar problem, an input panel with OK and Cancel buttons. If the user is editing a JTextField then clicks Cancel, you don't want the validation to kick in. I used this approach:
cancelButton.setVerifyInputWhenFocusTarget(false);
In your shoes I'd read the docs to see if ..setVerifyInputWhenFocusTarget(false) can be applied to your JMenuItems
.
- Follow-Ups:
- Re: How to detect focus lost on a JPanel
- From: Jeff Higgins
- Re: How to detect focus lost on a JPanel
- References:
- How to detect focus lost on a JPanel
- From: clearlight
- How to detect focus lost on a JPanel
- Prev by Date: menus
- Next by Date: Re: menus
- Previous by thread: How to detect focus lost on a JPanel
- Next by thread: Re: How to detect focus lost on a JPanel
- Index(es):