JDK-4048742 : Automatically restore focus when a window/dialog is reactivated
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1
  • Priority: P3
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_95
  • CPU: x86
  • Submitted: 1997-04-30
  • Updated: 2001-08-02
  • Resolved: 2001-08-02
Related Reports
Relates :  
Description

Name: sgC58550			Date: 04/30/97


Usually, when a window/dialog is re-activated, the focus is expected to reappear exactly where it was. 
GUI programmers shouldn't worry about this.

======================================================================

Comments
WORK AROUND Name: sgC58550 Date: 04/30/97 ======================================================================
11-06-2004

EVALUATION This has always been the intended behavior. Unfortunately, the implementation is buggy. I am reclassifying this as a bug. We intend to fix this for merlin. david.mendenhall@eng 1999-12-14 This problem can be reproduced with this test ======================================================================= import java.applet.*; import java.awt.*; import java.awt.event.*; import java.io.*; public class keytest extends Frame { private Button glc = null; private Frame frame = null; public static void main( String argv[] ) { keytest d = new keytest(); d.startDemo(); } public keytest() { super("Test"); frame = this; } public void startDemo() { setLayout( new BorderLayout() ); glc = new Button( "Testing" ); glc.addFocusListener(new FocusAdapter()); add( "Center", glc ); /** Register the keyboard listener */ KeyListener kl = new KeyAdapter() { public void keyPressed( KeyEvent evt ) { final Frame d = new Frame("Dialog"); d.addWindowListener(new WindowFocusAdapter()); Button b = new Button("close"); b.addFocusListener(new FocusAdapter()); b.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent ke) { System.err.println("-------------------------"); d.setVisible(false); } }); d.setLocation(100, 100); d.add(b); d.pack(); d.show(); } }; glc.addKeyListener( kl ); this.addWindowListener(new WindowFocusAdapter()); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); pack(); show(); } } class FocusAdapter implements FocusListener { public void focusLost(FocusEvent fe) { System.out.println("Focus lost on "+((Component)fe.getSource()).getName()); } public void focusGained(FocusEvent fe) { System.out.println("Focus gained on "+((Component)fe.getSource()).getName()); } } class WindowFocusAdapter extends WindowAdapter { public void windowGainedFocus(WindowEvent we) { System.err.println("windowGainedFocus on "+((Component)we.getSource()).getName()); } public void windowLostFocus(WindowEvent we) { System.err.println("windowLostFocus on "+((Component)we.getSource()).getName()); } public void windowActivated(WindowEvent we) { System.err.println("windowActivated on "+((Component)we.getSource()).getName()); } public void windowDeactivated(WindowEvent we) { System.err.println("windowDeactivated on "+((Component)we.getSource()).getName()); } } ======================================================================= I found two different problem (Win32 only): 1. start program, after start button in frame has focus, minimize and restore frame, after that button doesn't have focus. We have the same problem this Swing components (see 4380809) 2. start program, after start button in frame has focus, press any key, new frame will rise, but focus still on first frame. Looks like that this is similar problems. For some reason after activisation frame receives KILL_FOCUS. ###@###.### 2000-11-15 Name: rpR10076 Date: 08/02/2001 ###@###.### With merlin beta b73, the test from the comments section works as follows: Solaris-sparc: Correct behaviour. When we minimize/restore the initial frame, the focus is restored to the button correctly. If we create another frame, it becomes active. Windows: Almost correct behaviour: When we minimize/restore the initial frame, the focus is restored to the button correctly. When we create another frame, however, the focus stay on the initial frame. This is not the subject of this bug, though. ====================================================================== This was probably fixed by the focus rearchitecture we did in 1.4 Closing as no longer reproducible in 1.4. eric.hawkes@eng 2001-08-02
02-08-2001