AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Temporary focusLost behaves as permanent

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits
View previous topic :: View next topic  
Author Message
Anup
Guest





PostPosted: Fri Sep 16, 2005 10:00 pm    Post subject: Temporary focusLost behaves as permanent Reply with quote



I am encountering a very strange situation under jdk 1.4. In the
mousePressed method for a JButton, I requestFocus to a JTextField. Once
in a while I'm finding that upon exiting the method, the focus owner is
null and the permanent focus owner is the textfield. At that point
there is no focus on any component in the window - no blinking cursor
anywhere and the tab key does nothing. At the same time a temporary
focusLost event is received for the textfield. The first question is,
why does the textfield lose focus temporarily when I didn't even click
on another window? Having lost the focus, one would think it would
regain it since it is a temporary loss. However, going to another
window and coming back to this one doesn't help. The temporary loss
behaves as if it were permanent. Can anybody say why?

I have read over and over again that in a focusLost method one should
check for temporary events and disregard them. Should one also
disregard temporary events in the focusGained method?

Anup

Back to top
Andrey Kuznetsov
Guest





PostPosted: Fri Sep 16, 2005 10:09 pm    Post subject: Re: Temporary focusLost behaves as permanent Reply with quote



Quote:
I am encountering a very strange situation under jdk 1.4. In the
mousePressed method for a JButton, I requestFocus to a JTextField. Once
in a while I'm finding that upon exiting the method, the focus owner is
null and the permanent focus owner is the textfield. At that point
there is no focus on any component in the window - no blinking cursor
anywhere and the tab key does nothing. At the same time a temporary
focusLost event is received for the textfield. The first question is,
why does the textfield lose focus temporarily when I didn't even click
on another window? Having lost the focus, one would think it would
regain it since it is a temporary loss. However, going to another
window and coming back to this one doesn't help. The temporary loss
behaves as if it were permanent. Can anybody say why?

I have read over and over again that in a focusLost method one should
check for temporary events and disregard them. Should one also
disregard temporary events in the focusGained method?

May be it is your button takes temporary focus.
Try to JButton#setFocusable(false);

--
Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities



Back to top
Roedy Green
Guest





PostPosted: Sat Sep 17, 2005 1:53 am    Post subject: Re: Temporary focusLost behaves as permanent Reply with quote



On 16 Sep 2005 15:00:13 -0700, "Anup" <amullick (AT) telcordia (DOT) com> wrote
or quoted :

Quote:
I have read over and over again that in a focusLost method one should
check for temporary events and disregard them. Should one also
disregard temporary events in the focusGained method?

You need a microscope to see how this happens. Try adding debug code
to your focus listeners and insert sanity check code to detect the
damage.

A general comment. Focus has been a buggy area for Java and various
new ways of handling it appeared over time. I found setting up a
Focus Traversal policy was reliable.


see http://mindprod.com/jgloss/focus.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Back to top
Anup
Guest





PostPosted: Mon Sep 19, 2005 8:56 pm    Post subject: Re: Temporary focusLost behaves as permanent Reply with quote


Roedy Green wrote:
Quote:
On 16 Sep 2005 15:00:13 -0700, "Anup" <amullick (AT) telcordia (DOT) com> wrote
or quoted :

A general comment. Focus has been a buggy area for Java and various
new ways of handling it appeared over time. I found setting up a
Focus Traversal policy was reliable.


see http://mindprod.com/jgloss/focus.html

I looked at this page. It won't be easy figuring out how the focus got
lost temorarily, but once this happens, the user seems to have no
ability to regain it. Calling requestFocus didn't work either. Is there
another way to gain permanent focus programatically?

Anup


Back to top
Roedy Green
Guest





PostPosted: Tue Sep 20, 2005 7:25 am    Post subject: Re: Temporary focusLost behaves as permanent Reply with quote

On 19 Sep 2005 13:56:22 -0700, "Anup" <amullick (AT) telcordia (DOT) com> wrote
or quoted :

Quote:
Is there
another way to gain permanent focus programatically?

has someone done a Component.setFocusTraversalKeys(int, Set) orn
Container.setFocusCycleRoot(boolean)

Perhaps that overrides you.

what does isRequestFocusEnabled() say?

what does isFocusable() say?

Have you tried requestFocusInWindow()

Have you tried grabbing focus first to the container then to your
component?
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Back to top
Anup
Guest





PostPosted: Tue Sep 20, 2005 8:07 pm    Post subject: Re: Temporary focusLost behaves as permanent Reply with quote


Roedy Green wrote:
Quote:
On 19 Sep 2005 13:56:22 -0700, "Anup" <amullick (AT) telcordia (DOT) com> wrote
or quoted :

Is there
another way to gain permanent focus programatically?

has someone done a Component.setFocusTraversalKeys(int, Set) orn
Container.setFocusCycleRoot(boolean)

Perhaps that overrides you.

On every component, I'm doing the following:
HashSet forwardTraversalKeys = new HashSet();
forwardTraversalKeys.clear();
forwardTraversalKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
InputEvent.CTRL_MASK));
comp_.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
forwardTraversalKeys);
// similar for backward traversal
But I don't see why it would override mouse clicks.


Quote:
what does isRequestFocusEnabled() say?

true


Quote:
what does isFocusable() say?
Have you tried requestFocusInWindow()

I changed the code to
if (comp.isEnabled() && comp.isVisible() && comp.isFocusable())
comp.requestFocus(); // still didn't work
Also tried
boolean willFocus = comp.requestFocusInWindow();
willFocus returned true but the focus didn't transfer.


Quote:
Have you tried grabbing focus first to the container then to your
component?

Tried this also, as in
Component parent = comp.getParent();
Component dummy;
boolean continueNow = true;
while (parent != null && continueNow) {
if (parent.isEnabled() && parent.isVisible() &&
parent.isFocusable()) {
parent.requestFocus();
continueNow = false;
}
dummy = parent.getParent();
parent = dummy;
}
if (comp.isEnabled() && comp.isVisible() && comp.isFocusable())
comp.requestFocus(); // still didn't work


Even invokeLater on comp.requestFocus didn't work. One thing I did
notice is that just prior to failure, permanent focus was being
transferred from a certain component to itself. FocusLost and
focusGained got invoked consecutively for the same component, in
tandem. The component and the opposite were the same. When all was said
and done, focusOwner = null and permanentFocusOwner = component in
question. This could not be changed with any kind of user originated
action. Since no component had keyboard focus, keystrokes including tab
were ignored. Mouse clicks were acknowledged without the focus being
changed.


Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.