Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4048742
Votes 1
Synopsis Automatically restore focus when a window/dialog is reactivated
Category java:classes_awt
Reported Against 1.1
Release Fixed
State 11-Closed, Not Reproducible, bug
Priority: 3-Medium
Related Bugs 4380809
Submit Date 30-APR-1997
Description




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.

======================================================================
Work Around





======================================================================
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.
  xxxxx@xxxxx   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.

  xxxxx@xxxxx   2000-11-15



  xxxxx@xxxxx  
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.  
  xxxxx@xxxxx   2001-08-02
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang