Focus on JInternalFrame

I have been unable to give focus to a JInternalFrame no matter what I do.  Perhaps I'm missing something, but even calling setFocusOwner(jif) doesn't do any good.  Can someone recommend a way to do this?



darkfrog

I may be missing something, but dont you implement a focuslistener, then ahve a method something like :-


private void setFocus() {
      canvas.addFocusListener(new FocusListener() {
         public void focusGained(FocusEvent e) {
            ((AWTKeyInput)KeyInput.get()).setEnabled(true);
            ((AWTMouseInput)MouseInput.get()).setEnabled(true);
         }
         public void focusLost(FocusEvent e) {
            ((AWTKeyInput)KeyInput.get()).setEnabled(false);
            ((AWTMouseInput)MouseInput.get()).setEnabled(false);
         }
      });
   }

I don't think you understand my problem.  I want to give the JInternalFrame focus.  I want the top of the frame to highlight focused instead of keep the "blurred" color.  I can give items focus inside the JInternalFrame but the JInternalFrame still does not receive focus like it should.  However, if I use the mouse to click on the JInternalFrame or in one of the fields the JInternalFrame receives focus like it should.  I need a programmatic way of activating the JInternalFrame.



darkfrog

Simply do a setSelected( true ) on the internal frame  :slight_smile:

But I have added this to setFocusOwner, too, to get the expected behaviour.

Great, thanks buddy. :wink:



darkfrog