-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
1.3.0
-
x86
-
windows_nt
Name: sg39081 Date: 10/29/99
I built a JPopupMenu with three levels. I tried opening the levels at various places on the panel. Eventually, the sub-levels
began to appear at strange places on the screen -- sometimes far away from the previous level's menu.
The problem appears quickly when there are multiple JPanels that house JPopupMenus -- especially when one
switches back and forth between JFrames that house the JPanels.
I have a JPG screen-shot of the bug. It shows how the second level menu appears below and to the right of
the first level menu. I can send this image if needed.
I discovered this problem with the JDK1.2.2 plugin and began investigating on other JVMs. The 1.3beta
plugin has the same problem. The Appletviewers for JDK1.2.2 and 1.3 (early release and beta) demonstrate the problem readily.
When I tried the following code as an Application, it worked fine under JDK1.2.2 and 1.3 (early release and beta).
Here is how to reproduce the bug. Compile PTest.java and PPanel.java and put the class files in PTest.jar. To
test as an application, pass "PTest" on the java command line. To test in the appletviewer, pass "PTest2.html"
to the appletviewer. To test in the plugin, point the browser to PTest.html.
Two frames will appear. Try moving them around and switching back and forth between frames opening the
popup. When testing, be sure to open the popup menu at several places around the frame and drag the menus out to all levels.
The files you need are listed below.
---------------------------------------------------------------------- PTest.html -------------------------------------------------------------
<html>
<head>
<title>Popup Menu Test</title>
</head>
<body>
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
width="300" height="300" align="baseline"
codebase="http://java.sun.com/products/plugin/1.2/jinstall-12-win32.cab#Version=1,2,0,0">
<PARAM NAME="java_archive" VALUE="PTest.jar">
<PARAM NAME="code" VALUE="PTest">
<PARAM NAME="FrameFlag" VALUE="TRUE">
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.2">
No JDK 1.2 support for APPLET!!
</OBJECT>
</body>
</html>
---------------------------------------------------------------------- PTest2.html -------------------------------------------------------------
<head>
<title>Popup Menu Test</title>
</head>
<body>
<Applet width="300" height="300" code="PTest">
<PARAM NAME="archive" VALUE="PTest.jar">
<PARAM NAME="FrameFlag" VALUE="TRUE">
</Applet>
</body>
</html>
---------------------------------------------------------------------- PTest.java -------------------------------------------------------------
import javax.swing.*;
import java.awt.*;
public class PTest extends JApplet
{
public void init()
{
String flag = getParameter("FrameFlag");
if(flag!=null && flag.toUpperCase().equals("TRUE")) {
main(null);
} else {
getContentPane().setLayout(new BorderLayout());
getContentPane().add(new PPanel(),BorderLayout.CENTER);
}
}
public static void main(String [] args)
{
PPanel pp1 = new PPanel();
PPanel pp2 = new PPanel();
JFrame jf1 = new JFrame("Popup Panel Test1");
jf1.getContentPane().add(pp1,BorderLayout.CENTER);
jf1.setSize(640,480);
jf1.setVisible(true);
JFrame jf2 = new JFrame("Popup Panel Test2");
jf2.getContentPane().add(pp2,BorderLayout.CENTER);
jf2.setSize(640,480);
jf2.setVisible(true);
}
}
---------------------------------------------------------------------- PPanel.java -------------------------------------------------------------
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class PPanel extends JPanel implements MouseListener
{
JPopupMenu jPopup;
public PPanel()
{
setLayout(new BorderLayout());
add(new JLabel("Popup Panel",JLabel.CENTER),BorderLayout.CENTER);
jPopup = new JPopupMenu();
for(int x=0;x<10;++x)
{
JMenu jm = new JMenu("This is menu "+x);
for(int y=0;y<10;++y)
{
JMenu jm2 = new JMenu("This is submenu "+x+","+y);
for(int z=0;z<10;++z)
{
jm2.add(new JMenuItem("This is submenuitem "+x+","+y+","+z));
}
jm.add(jm2);
}
jPopup.add(jm);
}
addMouseListener(this);
}
public void mousePressed(MouseEvent e) { checkPopup(e); }
public void mouseClicked(MouseEvent e) { checkPopup(e); }
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseReleased(MouseEvent e) { checkPopup(e); }
int numberOpens = 0;
protected void checkPopup(MouseEvent e)
{
if(e.isPopupTrigger()) {
System.out.println("Raise count: "+numberOpens++);
JComponent jc = (JComponent)e.getSource();
jPopup.show(jc,e.getX(),e.getY());
}
}
}
(Review ID: 96370)
======================================================================