JDK-6269935 : JScrollPane, scroll bar not working for JMenu
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_8
  • CPU: x86
  • Submitted: 2005-05-13
  • Updated: 2010-04-02
  • Resolved: 2005-06-07
Related Reports
Duplicate :  
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

Comments
EVALUATION I think this may be the same problem as 5036146. ###@###.### 2005-05-26 19:00:49 GMT Actually, it is. Fix for 5036146 eliminates this bug also. Closing as duplicate. ###@###.### 2005-06-07 09:02:07 GMT
26-05-2005