Unwanted Focus Event

Discussion in 'Java' started by Bill Dennis, Jun 3, 2004.

  1. Bill Dennis

    Bill Dennis Guest

    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
     
    Bill Dennis, Jun 3, 2004
    #1
    1. Advertising

  2. Bill Dennis

    Kleopatra Guest

    Bill Dennis wrote:
    >
    > 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.
     
    Kleopatra, Jun 4, 2004
    #2
    1. Advertising

  3. On Fri, 04 Jun 2004 09:48:34 +0200, Kleopatra wrote:

    > Could you provide a small (!) compilable runnable example that
    > demonstrates the problem?


    Check here for tips on preparing that example..
    <http://www.physci.org/codes/sscce.jsp>

    [ ..which I would strongly suggest, since your
    post has apparently grabbed the attention of
    one of the Swing Guru's. ]

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, Jun 4, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sanjay patil via .NET 247

    Previous(Unwanted) event handled when page refreshed by key F5

    sanjay patil via .NET 247, Apr 27, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    403
    sanjay patil via .NET 247
    Apr 27, 2004
  2. Jason
    Replies:
    4
    Views:
    1,644
    Jason
    May 7, 2007
  3. Replies:
    2
    Views:
    346
    Thomas 'PointedEars' Lahn
    Jun 6, 2005
  4. Roger
    Replies:
    3
    Views:
    345
  5. Jeff

    manual focus vs. focus()

    Jeff, May 20, 2007, in forum: Javascript
    Replies:
    4
    Views:
    189
Loading...

Share This Page