Re: Help Menu - opens frame which does not go to front



Ian Wilson wrote:
Andrew Thompson wrote:

The OP might try calling toFront() and requestFocus() *after*
the dialog is visible..


I wonder if SwingUtilities.invokeLater may be of some relevance?

http://forum.java.sun.com/thread.jspa?threadID=666890&messageID=3905383

I use this idiom for a slightly related issue:
SwingUtilities.invokeLater(new Runnable(){
public void run(){
[component].requestFocusInWindow();
}
});

Even though the requestFocusInWindow() method is not really relevant here (it serves the purpose of moving focus to a particular component within the window - not the window itself), this message reminded me of some discussions we had in this newsgroup several years ago - maybe 2000/2001 or so (Don't know if Google still has those archives - and as to how relevant it would still be, because the focus subsystem in swing has undergone drastic changes since then).

Basically the issue used to be that a component would not accept / honour calls to requestFocus() till the Window was realized (or some time that was slightly later than this) - so the workaround was to wrap the requestFocus() call in a SwingUtilities.invokeLater wrapper so that the actual call would take place only during the next cycle of the EDT. And if I remember right, another solution that emerged during those discussions was that one could actually put in the requestFocus() call in a WindowOpened() eent handler of the window, and it would work fine (whereas it used to fail even if the call was immediately after the setVisible(true) call).

So may be the OP could try these workarounds :

1) Register a windowListener on this dialog and call toFront() from the windowOpened() event handler.

2) If that also doesn't work, try to delay the call by one more EDT cycle by wrapping it in an invokeLater wrapper.

BK
.



Relevant Pages

  • Re: JAI problem.
    ... > fails in Unix. ... > I read somewhere that requestfocus() is platform dependent method. ... make the Window that contains the component the focussed window. ...
    (comp.lang.java.gui)
  • Re: Whats the deal with Sun and focus behavior?
    ... Java has had numerous bugs with focus behavior. ... Set a WindowListener on your window. ... Create a Runnable object whose runmethod actually does a requestFocus ... Use invoke later to delay the requestFocus until after Java sets what it ...
    (comp.lang.java.gui)
  • Re: Whats the deal with Sun and focus behavior?
    ... Java has had numerous bugs with focus behavior. ... Set a WindowListener on your window. ... Create a Runnable object whose runmethod actually does a requestFocus ... Use invoke later to delay the requestFocus until after Java sets what it ...
    (comp.lang.java.gui)
  • Re: Whats the deal with Sun and focus behavior?
    ... this is pure fantasy on Sun's part. ... but then some stupidity in the focus system resets it to the Replace ... That is why you have to delay the requestFocus until after they ... > Window is set to be the active Window'. ...
    (comp.lang.java.gui)
  • READ CYCLE VFP7 vs VFP8
    ... in several programs vfp6 and vfp7 that we found easy and ... with button colors etc. untill the READ CYCLE is reached. ... Then the content inside the window disapear, ... Does any one know what is the difference between vfp7 and 8 ...
    (microsoft.public.fox.helpwanted)