Unwanted Focus Event

B

Bill Dennis

I've got a glitch in my code that I just can't track down. When
editing a table cell, if I then click on (or even cursor to) another
table cell, a JTextField on the screen (not in the table), momentarily
gets focus, then focus jumps back to the table. I've found that when
I press the mouse key, focus jumps to the field, then when I release
the mouse key, focus goes back to the table. I've tried overriding
the requestFocus() and grabFocus() methods of the JTextField, and even
the focusNextComponent() method of the FocusManager, but none of them
is being called. Yet the focusLost() and focusGained() methods of the
JTextField's FocusListener are being invoked. I can't figure out
where the FocusEvent is coming from, thought I'm thinking it must be
somewhere in my code, though I've put in some println's everywhere
that I create a FocusEvent, and none of them is being called either.
How can I find out what is causing the focusLost() and focusGained()
to be called (i.e., who is adding the FocusEvents to the EDT)?
Thanks.

Bill Dennis
 
K

Kleopatra

Bill said:
I've got a glitch in my code that I just can't track down. When
editing a table cell, if I then click on (or even cursor to) another
table cell, a JTextField on the screen (not in the table), momentarily
gets focus, then focus jumps back to the table. I've found that when
I press the mouse key, focus jumps to the field, then when I release
the mouse key, focus goes back to the table. I've tried overriding
the requestFocus() and grabFocus() methods of the JTextField, and even
the focusNextComponent() method of the FocusManager, but none of them
is being called. Yet the focusLost() and focusGained() methods of the
JTextField's FocusListener are being invoked. I can't figure out
where the FocusEvent is coming from, thought I'm thinking it must be
somewhere in my code, though I've put in some println's everywhere
that I create a FocusEvent, and none of them is being called either.
How can I find out what is causing the focusLost() and focusGained()
to be called (i.e., who is adding the FocusEvents to the EDT)?

Sounds weird - but not very much so: there are loads of focus/editing
related glitches in JTable (never ran into this particular one, though).
Could you provide a small (!) compilable runnable example that
demonstrates the problem?

Alternatively you can track all focus events by registering a
PropertyChangeListener with the KeyboardFocusManager on the
(permanent)focusOwner property - I suspect the table to do a
requestFocus when editing is terminated, just a guess, though.

Greetings
Jeanette

PS: a better place for Swing related questions is comp.lang.java.gui
because it's focused on gui issues. You might consider asking there next
time.
 

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,995
Messages
2,570,231
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top