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

JPopupMenu getPopupMenuOrigin miscalculates Y position

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.1
    • client-libs



      Name: yyT116575 Date: 08/02/2001


      java version "1.3.0_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_02)
      Java HotSpot(TM) Client VM (build 1.3.0_02, mixed mode)


      This problem is similiar to sun bugs 4236438 and 4242461.

      The problem is on line 391 of javax.swing.JMenu, which reads:

      y = 0-pmSize.height


      y is the where the origin of the popup menu should be. pmSize is the dimensions
      of the popup menu. This code is run when the popup menu is too long and needs
      to be showing going 'up' as opposed to downward. The problem is, in windows you
      are not guaranteed that 0-pmSize.height is not somewhere off the top of the
      screen. What it should be is 0-parentScreenLocation.y.

      Reproducing this problem is very simple. The following application will
      reproduce this problem. Run this app in windows giving it one argument, the num
      menu items. Do not make the items so many that the elements will always spill
      off the screen. Make it so the menu height is about 60% of the screen height.
      Then move the window to the middle of the screen, forcing the menu to be
      displayed 'up'.

      import javax.swing.*;

      public class MenuProblem extends JFrame {
        public JMenu m;
        public MenuProblem(int numItems) {
        JMenuBar mb = new JMenuBar();
        m = mb.add(new JMenu("File"));
        for(int i=0; i<numItems; i++) {
          m.add(String.valueOf(i));
        }
        setJMenuBar(mb);
      }

        public static void main(String[] args) {
          int numItems = 20;
          if(args.length > 0) {
            //assuming arg is num menu items
            try {
              numItems = Integer.parseInt(args[0]);
            } catch(Exception e) {
            }
          }
          MenuProblem jf = new MenuProblem(numItems);
          jf.setSize(200, 200);
          jf.setTitle("Adv. Menu Example");
          jf.setVisible(true);
        }
      }
      (Review ID: 126639)
      ======================================================================

            peterz Peter Zhelezniakov
            yyoungsunw Yung-ching Young (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: