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

JWindow does not allow its children to get keyboard focus on Solaris

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      solaris_2.5

      Description

      I have a Window that has a single child a TextArea.
      This TextArea never gets a keyboard focus, no matter what on Solaris.
      The bug seems to be both in Swing's JWindow and AWT's Window.
      Since JWindow is a subclass of Window.

      I have trested with both JDK 1.1 and 1.2. It does not work.

      This works fine on Win32.

      Here are the codes for both of them.


      /*
      File: WindowBug.java
      AWT implementation
      */

      import java.awt.Dimension;
      import java.awt.event.WindowAdapter;
      import java.awt.event.WindowEvent;
      import java.awt.event.*;
      import java.awt.Color;
      import java.awt.*;

      public class WindowBug {

              public final Window window ;
              public final Button button ;
              public final TextArea text ;

          public WindowBug() {
              Frame frame = new Frame("WindowBug");
              frame.addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {System.exit(0);}});

              window = new Window(frame);
              button = new Button("Press Me");
              text = new TextArea(10, 50);

              frame.add(button);
              window.setLayout(new BorderLayout());
              window.add( text, BorderLayout.CENTER);
              button.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ev) {
                      window.setSize(new Dimension(300, 200));
                      window.setLocation(button.getLocationOnScreen().x , button.getLocationOnScreen().y +
                               button.getSize().height);
                      window.setVisible(true);
                      text.requestFocus();
                      text.append("\n Hello there ");
                  }
              });

              frame.setSize(150, 150);
              frame.setLocation( new Point(150, 150));
              frame.setVisible(true);
          }

          public static void main(String[] args) {
              new WindowBug();
          }

      }


      /*
      File: JWindowBug.java
      Swing implementation
      */


      import com.sun.java.swing.*;

      import java.awt.Dimension;
      import java.awt.event.WindowAdapter;
      import java.awt.event.WindowEvent;
      import java.awt.event.*;
      import java.awt.Color;
      import java.awt.*;

      public class JWindowBug {

              public final JWindow window ;
              public final JButton button ;
              public final JTextArea text ;

          public JWindowBug() {
              JFrame frame = new JFrame("JWindowBug");
              frame.addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {System.exit(0);}});

              window = new JWindow(frame);
              button = new JButton("Press Me");
              text = new JTextArea(10, 50);

              frame.getContentPane().add(button);
              window.getContentPane().setLayout(new BorderLayout());
              window.getContentPane().add( text, BorderLayout.CENTER);
              button.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ev) {
                      window.setSize(new Dimension(300, 200));
                      window.setLocation(button.getLocationOnScreen().x , button.getLocationOnScreen().y +
                               button.getSize().height);
                      window.setVisible(true);
                      text.grabFocus();
                      text.append("\n Hello there ");
                  }
              });

              frame.setSize(150, 150);
              frame.setLocation( new Point(150, 150));
              frame.setVisible(true);
          }

          public static void main(String[] args) {
              new JWindowBug();
          }

      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                duke J. Duke (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: