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

Bug in javax.swing.plaf.basic.BasicComboPopup.computePopupBounds(int,int,int,int

XMLWordPrintable

      Name: js151677 Date: 08/26/2004


      FULL PRODUCT VERSION :
      java version "1.4.2_04"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
      Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      When a BasicComboPopup is long enough to go off the bottom of the screen, instead of doing something smart, computePopupBounds just moves it up by its height. In 1.3, this often resulted in the popup menu going off the top edge of the screen, but in 1.4 JPopupMenu has been modified to correct the bounds of the popup, preventing it from going off the top of the screen. Even though the popup menu no longer goes off the top of the screen, its behavior is still not desirable, because the location where a long popup is displayed is so different from the normal location for a popup. In 1.4, JPopupMenu is much smarter about how it keeps popups from going off the screen than computePopupBounds is, so it would be best if computePopupBounds didn't do anything.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use any JComboBox whose popup menu is long enough to go off the bottom of the screen. This requires setting the maximumRowCount of the JComboBox to a much higher value than its default.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Ideally, the popup menu should be moved up just enough to keep its bottom edge from going off the bottom of the screen, and no more.
      ACTUAL -
      Instead, the popup menu is moved up by a value equal to its height.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import javax.swing.*;

      public class ShowPopupBug {
      public static void main (String[] args) {
      JPanel contentPane = new JPanel(new BorderLayout());
      String[] items = new String[50];
      for (int i = 0; i < items.length; i += 1)
      items[i] = "Menu Item " + (i+1);
      JComboBox menu = new JComboBox(items);
      menu.setMaximumRowCount(50);
      contentPane.add(menu, BorderLayout.CENTER);
      contentPane.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
      JFrame frame = new JFrame("Popup Bug Demo");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setContentPane(contentPane);
      frame.pack();
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      frame.setLocation(new Point(10 + (int)((screenSize.width - frame.getWidth()) / 2),
      30 + (int)((screenSize.height - frame.getHeight()) / 2)));
      frame.setVisible(true);
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      I have created my own subclass of MetalComboBoxUI that specializes the createPopup method, returning an instance of a subclass of BasicComboPopup whose computePopupBounds does no screen-boundary checking. This works as long as I'm using the Metal L&F, but will not work for other L&F's which subclass BasicComboBoxPopup. This has required us to remove support for other L&F's from our product.
      (Incident Review ID: 300838)
      ======================================================================

            Unassigned Unassigned
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: