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

JRootPane is added twice in JInternalFrame

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.2.2
    • client-libs
    • beta
    • x86
    • windows_nt



      Name: et89391 Date: 08/19/99


      If an applications replaces the root pane of an
      JInternalFrame, then the root pane is added twice to
      the JInternalFrame.

      Repeat-by:

      o compile T02

      o run T02
      it creates a desktop containing one InternalFrame

      o The program uses a subclass of JInternalFrame for the internal frame.

      The method addImpl() is overridden and writes a log message
      each time it is called.

      o the program writes:
      addImpl: adding (javax.swing.JRootPane)RootPane1 constraints=Center index=-1
      addImpl: adding (javax.swing.JRootPane)RootPane1 constraints=Center index=-1
      addImpl: adding (javax.swing.plaf.basic.BasicInternalFrameTitlePane)null constraints=null index=-1

      showing that the root pane is added twice to the internal frame


      Reason:
      the method setRootPane() adds the rootpane, and fires a PropertyChangeEvent
      ROOT_PANE_PROPERTY to all listeners.
      One listener is attached by the BasicInternalFrameUI. It is an instance
      of BasicInternalFrameUI.InternalFramePropertyChangeListener.
      In its methode propertyChange it reacts on ROOT_PANE_PROPERTY changes
      by removing the old rootpane and adding the new rootpane.
      Thus the rootpane is added twice when setRootPane is called.


      T02.java
      ========

      /*
       */

      import java.awt.*;
      import java.awt.event.*;

      import javax.swing.*;
      import javax.swing.event.*;

      public class
      T02
      extends JFrame
      {

      JRootPane rp;
      T02DesktopPane dtp;

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

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

      private static void
      dbg(String s)
      {
      System.out.println ("T02: "+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 T02DesktopPane(400, 400);
      rp = new T02RP(dtp);
      rp.setName("RootPane1");
      setRootPane(rp);

      T02IF iframe1 = new T02IF("Frame1");

      dtp.add(iframe1, 1, 1);
      }

      }

      class T02RP
      extends JRootPane
      {
      public T02RP(JDesktopPane dtp)
      {
      getContentPane().setLayout(new BorderLayout());
      getContentPane().add(dtp, BorderLayout.CENTER);
      setName("RootPane1");
      }
      }

      class T02IF
      extends JInternalFrame
      {
      public T02IF(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);
      }

      protected void addImpl(Component comp, Object constraints, int index)
      {
      System.out.println("addImpl: adding ("+comp.getClass().getName()+")"+comp.getName()+" constraints="+constraints+" index="+index);
      super.addImpl(comp, constraints, index);
      }

      static int count = 1;
      protected JRootPane createRootPane()
      {
      int i = count++;
      JRootPane rp = new JRootPane();
      rp.setName("RootPane"+i);

      return rp;
      }
      }


      class T02DesktopPane
      extends JDesktopPane
      {
      public T02DesktopPane(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: 93210)
      ======================================================================

            joutwatesunw Joshua Outwater (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: