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

PopupFactory creates a heavy weight popup menu if application is not maximized

    XMLWordPrintable

    Details

      Description

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

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Multiple Monitor extended desktop environment

      A DESCRIPTION OF THE PROBLEM :
      In the PopupFactory fitsOnScreen method is only testing if the popup is in it's parent container. Not if it will actually fit on the screen or even fit in the parent component. This causes the PopupFactory to unnecessarily return a heavy weight popup component.

      Two possible fixes that would make the behavior better would be to
      1) check to see if the popup will fit in the parent frame component and if so move the popup inside
      2) check to see if the popup will fit on the screen if so move it onto the screen and let it render

      Currently if the frame's extended state is Maximized_both then the popup will be moved inside the frame prior to checking to see if it will fit. This causes the popup to correctly return a lightweight component. It would be nice if the popups behaved the same regardless of the frame's extended state.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a jframe view, put a button with an icon in borderlayout east. when the button is pushed create a jpopupmenu and show the menu. If the frame is maximized it will create a jpopupmenu rooted in the lightweight jframe. If the frame is not maximized the jpopupmenu will be rooted in a Popup$HeavyWeightWindow

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Both states of the frame should create a jpopupmenu rooted in a lightweight component (a lightweight popup)
      ACTUAL -
      Depending on the frame's extended state a different type of popupmenu is created.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.BorderLayout;
      import java.awt.event.ActionEvent;

      import javax.swing.*;

      public class JPopupTest {
          public static void main(String[] args) {
      JFrame frame = new JFrame();
      frame.getContentPane().setLayout(new BorderLayout());
      final JButton button = new JButton("test");
      button.setAction(new AbstractAction("test") {

      public void actionPerformed(ActionEvent e) {
      JPopupMenu popup = new JPopupMenu("This is a label for the menu");
      popup.add(new JMenuItem("test item"));
      popup.show(button, 0, 0);
      System.out.println("Stop here to see if the popup field in JPopupMenu is HeavyWeight or LightWeight");
      }
      });
      frame.getContentPane().add(button,BorderLayout.EAST);
      frame.setSize(500,500);
      frame.setVisible(true);
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Set the location of the jpopupmenu to be inside the frame prior to calling show

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Imported:
              Indexed: