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

JScrollPane, scroll bar not working for JMenu

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 5.0
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:

      Description

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


      ADDITIONAL OS VERSION INFORMATION :
      SunOS asia 5.8 Generic_117350-23 sun4u sparc SUNW,Sun-Blade-1000


      A DESCRIPTION OF THE PROBLEM :
      Want a scrollable menu. Created a JList added it to a JScrollPane, added the JScrollPane to a JMenu. The menu is scrollable but the scroll bar does not work. Selecting the triangle on either end of the list causes scrolling to the very bottom or top (does not stop) and can not move the scrollbar.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Here is code to demonstrate the problem:



      import javax.swing.*;
      import java.awt.event.*;


      public class ScrollMenu extends JFrame {
           JMenuBar menuBar;
           JMenu menu1;
           JMenu menu2;
           JMenu menu3;
           JList list;

           /** Creates a new instance of ScrollMenu */
           public ScrollMenu() {
               menuBar = new JMenuBar();
               menu1 = new JMenu("Menu 1");
               menu2 = new JMenu("Menu 2");
               menu3 = new JMenu("Menu 3");

               for (int i=0; i<5; i++) {
                   menu1.add(new JMenuItem("Eintrag "+String.valueOf(i+1)));
                   menu3.add(new JMenuItem("Eintrag "+String.valueOf(i+1)));
               }

               DefaultListModel m=new DefaultListModel();
               list = new JList(m);

               for (int i=0; i<100; i++) {
                   m.addElement("Eintrag "+String.valueOf(i+1));
               }

               menu2.add(new JScrollPane(list));

               menuBar.add(menu1);
               menuBar.add(menu2);
               menuBar.add(menu3);
               setJMenuBar(menuBar);

               list.addMouseListener(new MouseAdapter() {
                   public void mousePressed(MouseEvent evt) {
                       int index = list.locationToIndex(evt.getPoint());
                       list.setSelectedIndex(index);
                       menu2.setPopupMenuVisible(false);
                       menu2.setSelected(false);

                       System.out.println(index);
                   }
               });

               list.addMouseMotionListener(new MouseMotionAdapter() {
                   public void mouseMoved(MouseEvent evt) {
                       int index = list.locationToIndex(evt.getPoint());
                       list.setSelectedIndex(index);
                   }
               });

               addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent evt) {
                       System.exit(0);
                   }
               });

               pack();
           }

           public static void main(String[] args) {
               new ScrollMenu().show();
           }
      }



      REPRODUCIBILITY :
      This bug can be reproduced always.

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


      public class ScrollMenu extends JFrame {
           JMenuBar menuBar;
           JMenu menu1;
           JMenu menu2;
           JMenu menu3;
           JList list;

           /** Creates a new instance of ScrollMenu */
           public ScrollMenu() {
               menuBar = new JMenuBar();
               menu1 = new JMenu("Menu 1");
               menu2 = new JMenu("Menu 2");
               menu3 = new JMenu("Menu 3");

               for (int i=0; i<5; i++) {
                   menu1.add(new JMenuItem("Eintrag "+String.valueOf(i+1)));
                   menu3.add(new JMenuItem("Eintrag "+String.valueOf(i+1)));
               }

               DefaultListModel m=new DefaultListModel();
               list = new JList(m);

               for (int i=0; i<100; i++) {
                   m.addElement("Eintrag "+String.valueOf(i+1));
               }

               menu2.add(new JScrollPane(list));

               menuBar.add(menu1);
               menuBar.add(menu2);
               menuBar.add(menu3);
               setJMenuBar(menuBar);

               list.addMouseListener(new MouseAdapter() {
                   public void mousePressed(MouseEvent evt) {
                       int index = list.locationToIndex(evt.getPoint());
                       list.setSelectedIndex(index);
                       menu2.setPopupMenuVisible(false);
                       menu2.setSelected(false);

                       System.out.println(index);
                   }
               });

               list.addMouseMotionListener(new MouseMotionAdapter() {
                   public void mouseMoved(MouseEvent evt) {
                       int index = list.locationToIndex(evt.getPoint());
                       list.setSelectedIndex(index);
                   }
               });

               addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent evt) {
                       System.exit(0);
                   }
               });

               pack();
           }

           public static void main(String[] args) {
               new ScrollMenu().show();
           }
      }
      ---------- END SOURCE ----------
      ###@###.### 2005-05-13 10:46:33 GMT

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              kizune Alexander Zuev
              Reporter:
              jssunw Jitender S (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: