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

Maximization state of JInternalFrames is corrupted by WindowsDesktopManager

    XMLWordPrintable

Details

    • Fix Understood
    • x86
    • windows_vista

    Description

      FULL PRODUCT VERSION :
      java version "1.6.0_04"
      Java(TM) SE Runtime Environment (build 1.6.0_04-b12)
      Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows Vista Ultimate (but the behavior should be prevalent on any windows platform)

      A DESCRIPTION OF THE PROBLEM :
      Given a swing MDI application. If one internal frame is open and maximized and another internal frame is created which is initialized with setMaximum(true) then after opening the second internal frame both internal frames are non-maximized.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute the test case. Press the button on the internal frame. A second internal frame is created and opened.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The second internal frame should be maximized. (Because it is initialized with maximum flag set to true.)
      ACTUAL -
      Both internal frames are non-maximized.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;
      import java.beans.PropertyVetoException;

      import javax.swing.*;
      import javax.swing.plaf.metal.MetalLookAndFeel;

      import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;

      public class ReproduceInternalFrameBug
      {
      public static void main(String[] args)
      {
      try
      {
      UIManager.setLookAndFeel(WindowsLookAndFeel.class.getName());

      // try this out for comparison:
      // UIManager.setLookAndFeel(MetalLookAndFeel.class.getName());
      }
      catch (Exception e)
      {
      System.err.println("Could not load LookAndFeel");
      }

      final JDesktopPane pane = new JDesktopPane();
      final JInternalFrame internal = new JInternalFrame("the first internal frame", true, true, true, true);
      pane.add(internal);
      internal.setBounds(0, 0, 200, 100);
      try
      {
      internal.setMaximum(true);
      }
      catch (PropertyVetoException e)
      {
      e.printStackTrace();
      }
      internal.setVisible(true);
      JButton button = new JButton("open another internal frame");
      button.addActionListener(new ActionListener()
      {
      public void actionPerformed(ActionEvent evt)
      {
      final JInternalFrame internal2 = new JInternalFrame("another one", true, true, true, true);
      pane.add(internal2);
      internal2.setBounds(250, 150, 200, 100);
      try
      {
      internal2.setMaximum(true);
      }
      catch (PropertyVetoException e)
      {
      e.printStackTrace();
      }
      internal2.setVisible(true);
      }
      });
      internal.add(button, BorderLayout.SOUTH);

      JFrame f = new JFrame("Example");
      Container cp = f.getContentPane();
      cp.add(pane, BorderLayout.CENTER);
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      f.setSize(800, 600);
      f.setLocationRelativeTo(null);
      f.setVisible(true);
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Look at class com.sun.java.swing.plaf.windows.WindowsDesktopManager into Method activateFrame(JInternalFrame):
      ...
                              currentFrame.setMaximum(false);
                              if (f.isMaximizable()) {
                                  if (!f.isMaximum()) {
                                      f.setMaximum(true);
                                  } else if (f.isMaximum() && f.isIcon()) {
                                      f.setIcon(false);
                                  } else {
                                      f.setMaximum(false);
                                  }
                              }
      ...
      Look at the else clause which sets maximum to false for the newly opened internal frame f if its maximum flag is already set to true and it is not iconified.

      So, one solution would be to set the maximum property for a newly created internal frame only after this code has been passed (which is after calling setVisible(true)).

      Another one would be to create another WindowsDesktopManager class which differs from the existing only in the else clause being commented out.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Imported:
                Indexed: