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

Regression: JInternalFrame not activated on mouse clicks if glassPane replaced

XMLWordPrintable

      Name: mc57594 Date: 10/26/99

      A JInternalFrame is not activated by mouse clicks in its
      interior.
       This happens if the glass pane (or the root pane
      and hence
      the glass pane too) of the internal frame has
      been replaced.

      Repeat by:

      o compile T01.java

      o run it

      o the program creates a Desktop with size 400x400.
        Inside the desktop there are two internal frames,
        Frame1 and Frame2

      o move the frames so that they overlap a little; it should be
        possible to see which frame is in the foreground, and it should
        be possible to click in them both.

      o click in Frame2 to bring it to the foreground

      o click in the FextField in Frame1

      ---> Frame2 is still showing as being activated, Frame1 does not
        come to the foreground. But it is possible to enter data
        in the TextField of frame1

      Reason:
      In jdk1.2.2 BasicInternalFrameUI the glassPaneDispatcher is
      attached to the glass pane permanently. When the Frame is
      deactivated, the glasspane becomes visible, the listener
      catches clicks and activates the frame. When the
      Frame is activated, the glasspane is made invisible.
      But when the RootPane or the GlassPane is replaced, the listener
      stays attached to the old glasspane.
      In jdk1.2 the glassPaneDispatcher was installed/uninstalled
      when the frame was deactivated/activated.


      T01.java
      ========

      /*
       * Demo of bug b058 in jdk1.2.2 final:
       * when a glasspane is substituted in an InternalFrame,
       * the frame is not activated by mouse clicks.
       */
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      public class
      T01
      extends JFrame
      {

      JRootPane rp;
      T01DesktopPane dtp;

      public static void
      main (String[] av)
      {
      T01 t1;

      t1 = new T01();
      t1.init();
      t1.pack();
      t1.show();
      }

      private static void
      dbg(String s)
      {
      System.out.println ("T01: "+s);
      }

      public void
      init()
      {
      Container cont;

      addWindowListener (
      new WindowAdapter() {
      public void windowClosing(WindowEvent e)
      {
      System.exit(0);
      }
      }
      );


      try {
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
      } catch (Exception ex) {
      System.out.println("Cannot set WindowsLookAndFeel; Exception : "+ex);
      System.out.println("Continue nevertheless.");
      }

      dtp = new T01DesktopPane(400, 400);
      rp = new T01RP(dtp);
      setRootPane(rp);

      T01IF iframe1 = new T01IF("Frame1");
      iframe1.setLocation(10, 10);
      T01IF iframe2 = new T01IF("Frame2");
      iframe1.setLocation(20, 30);

      dtp.add(iframe1, 1, 1);
      dtp.add(iframe2, 1, 2);

      iframe1.setNewGlassPane();
      }

      }

      class T01RP
      extends JRootPane
      {
      public T01RP(JDesktopPane dtp)
      {
      getContentPane().setLayout(new BorderLayout());
      getContentPane().add(dtp, BorderLayout.CENTER);
      }
      }

      class T01IF
      extends JInternalFrame
      {
      public T01IF(String title)
      {
      super(title);
      setName(title);
      init();
      pack();
      }

      private void init()
      {
      JPanel p = new JPanel();

      p.add(new JButton("push me"));
      p.add(new JTextField(12));

      getContentPane().add(p);
      }

      public void setNewGlassPane()
      {
      JComponent c = new JPanel();
      c.setName(this.getName()+".glassPane");
      c.setVisible(false);
      ((JPanel)c).setOpaque(false);
      System.out.println("Setting GlassPane");
      setGlassPane(c);
      }
      }


      class T01DesktopPane
      extends JDesktopPane
      {
      public T01DesktopPane(int w, int h)
      {
      setPreferredSize(new Dimension(w,h));
      }

      public void add(JInternalFrame frame, int layer, int pos)
      {
      setLayer(frame, layer, pos);
      int startidx = insertIndexForLayer(layer, pos);
      addImpl(frame, null, startidx);
      }
      }
      (Review ID: 93144)
      ======================================================================

            mbronsonsunw Mike Bronson (Inactive)
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: