Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4176602

Request Focus Fails with Consecutive Dialogs

XMLWordPrintable

    • 1.1.8
    • x86
    • windows_nt
    • Verified

      When the example below is compiled and run with JDK 1.1.7E on win32, the text field that requests the focus after the second dialog is dismissed fails to
      obtain it. This happens only on win32.

      -------------------------------- DoubleFocusAwt.java ---------------------------
      import java.awt.*;
      import java.awt.event.*;
      import java.net.*;

      public class DoubleFocusAwt extends Frame {

        public DoubleFocusAwt() {
          setSize(400, 300);
          setLayout(new FlowLayout());

          tf1.setColumns(10);
          tf2.setColumns(16);

          add(tf1);
          add(tf2);
          tf1.requestFocus();
          add(targetButton);

          targetButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
              tf1.setText("");
              tf2.setText("");
              doDlgSequence();
            }
          });
        }


        public static void main(String[] args) {
          
          DoubleFocusAwt bt = new DoubleFocusAwt();
          bt.setVisible(true);
          dlg1 = new Dlg(bt, "This is dialog 1");
        }

        public void doDlgSequence() {
          showDlg1();
          showDlg2();
        }

        public void showDlg1() {
          dlg1.setVisible(true);
        }

        public void showDlg2() {
          Dlg dlg2 = new Dlg(new Frame(), "This is dialog 2");
          dlg2.setVisible(true);
          tf1.requestFocus();
        }

        Button targetButton = new Button("Click Here");

        static Dlg dlg1 ;
        static Frame frame;

        TextField tf1 = new TextField("Tab to next");
        TextField tf2 = new TextField("Tab to next");

      }

      class Dlg extends Dialog {
        public Dlg(Frame frame, String str) {
          super(frame);
          setSize(200, 200);
          setLayout(new FlowLayout());
          add(new Label(str));
          add(button);
          setModal(true);
          button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
              setVisible(false);
            }
          });
        }

        Button button = new Button("OK");
      }

            rkhansunw Robi Khan (Inactive)
            nrodinsunw Nick Rodin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: