-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.3.0
-
x86
-
windows_nt
Name: skT45625 Date: 04/10/2000
C:\jdk1.3\bin>java -version
java version "1.3.0rc2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc2-Y)
Java HotSpot(TM) Client VM (build 1.3.0rc2-Y, mixed mode)
/*
This program illustrates a bug with Swing menus. The specific problem is that
null pointer exceptions are thrown and the menu option in question becomes
unusable.
The bug appears when a pulldown menu drops below the lower border of the frame
in which it resides. It does not matter if the menu was created larger than
the frame, or if the frame was resized to a small size during use.
This program illustrates the bug. Follow these steps:
1. Run JavaMenuBug
2. Click on Menu2. Notice that the menu extends beyone the bottom border
of the frame.
3. Slide the mouse down to the Sub-menu option until the pull-right menu
appears, however, leave the mouse over the Sub-menu label. Do not move
mouse over the pull-right menu.
4. Now, click on the "Sub-menu" option on Menu2. The first indicator of a
problem is that the title bar of the frame is greyed-out.
5. Now, close the menu by clicking elsewhere on the frame. Next, redisplay
Menu2 and move the mouse over the Sub-menu option. The DOS window will
explode with exceptions and the menu will not function correctly.
Now, close the application and re-start it:
1. Re-size the frame by dragging the bottom of the frame down, to make the
frame larger vertically than the pulldown menu. Now repeat the steps
above. The problem will not occur.
2. Re-size the window again, to make the frame shorter than Menu2, then try
the steps again. The problem will re-appear.
*/
package ssi.javabugs;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SubMenuBug extends JFrame
{
public SubMenuBug()
{
// Create menu bar
JMenuBar menuBar = new JMenuBar(); // Create menu bar
setJMenuBar(menuBar); // Add menu bar to window
// Create first option on menuBar
JMenu m1 = new JMenu("Menu1");
m1.setMnemonic('M');
JMenuItem m1o1 = new JMenuItem("Option1");
m1o1.setMnemonic('O');
m1o1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Menu1/Option1 was selected");
}
}
);
m1.add(m1o1);
JMenuItem m1o2 = new JMenuItem("Option2");
m1o2.setMnemonic('N');
m1o2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Menu1/Option2 was selected");
}
}
);
m1.add(m1o2);
// Create second option on menuBar
JMenu m2 = new JMenu("Menu2");
m2.setMnemonic('N');
JMenuItem m2o1 = new JMenuItem("Option1");
m2o1.setMnemonic('1');
m2o1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Menu2/Option1 was selected");
}
}
);
m2.add(m2o1);
JMenuItem m2o2 = new JMenuItem("Option2");
m2o2.setMnemonic('2');
m2o2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Menu2/Option2 was selected");
}
}
);
m2.add(m2o2);
// Create Sub-Menu
JMenu sm1 = new JMenu("Sub-menu");
sm1.setMnemonic('S');
JMenuItem smo1 = new JMenuItem("Sub menu option 1");
smo1.setMnemonic('O');
smo1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Sub-Menu/Option 1 was selected");
}
}
);
sm1.add(smo1);
JMenuItem smo2 = new JMenuItem("Sub menu option 2");
smo2.setMnemonic('N');
smo2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Sub-Menu/Option 2 was selected");
}
}
);
sm1.add(smo2);
m2.add(sm1);
JMenuItem m2o3 = new JMenuItem("Option3");
m2o3.setMnemonic('3');
m2o3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Menu2/Option1 was selected");
}
}
);
m2.add(m2o3);
JMenuItem m2o4 = new JMenuItem("Option4");
m2o4.setMnemonic('4');
m2o4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Menu2/Option1 was selected");
}
}
);
m2.add(m2o4);
JMenuItem m2o5 = new JMenuItem("Option5");
m2o5.setMnemonic('5');
m2o5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Menu2/Option1 was selected");
}
}
);
m2.add(m2o5);
JMenuItem m2o6 = new JMenuItem("Option6");
m2o6.setMnemonic('6');
m2o6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Menu2/Option1 was selected");
}
}
);
m2.add(m2o6);
JMenuItem m2o7 = new JMenuItem("Option7");
m2o7.setMnemonic('7');
m2o7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Menu2/Option1 was selected");
}
}
);
m2.add(m2o7);
JMenuItem m2o8 = new JMenuItem("Option8");
m2o8.setMnemonic('8');
m2o8.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Menu2/Option1 was selected");
}
}
);
m2.add(m2o8);
JMenuItem m2o9 = new JMenuItem("Option9");
m2o9.setMnemonic('9');
m2o9.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Menu2/Option1 was selected");
}
}
);
m2.add(m2o9);
JMenuItem m2o0 = new JMenuItem("Option0");
m2o0.setMnemonic('0');
m2o0.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Menu2/Option1 was selected");
}
}
);
m2.add(m2o0);
menuBar.add(m1);
menuBar.add(m2);
this.setTitle("Sub Menu Bug");
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
);
setSize(400,250);
show();
}
public static void main(String[] args)
{
SubMenuBug subMenuBug = new SubMenuBug();
}
}
###@###.### 2000-04-10
Was able to reproduce it on the Win NT machine but not on the Sparc Solaris.
(Review ID: 103495)
======================================================================
- duplicates
-
JDK-4280243 Kestrel I, jMenu app causes null pointer exceptions
-
- Closed
-