-
Bug
-
Resolution: Fixed
-
P3
-
m3, 1.1, 1.2.0, 1.2.2
-
kestrel
-
generic, x86, sparc
-
generic, solaris_2.5.1, solaris_10, windows_nt
Name: vi73552 Date: 06/03/99
>1.Exact steps to reproduce the problem.
If you create a JPopupMenu on a component of a modal
JDialog, the menu will be clipped to display within the JDialog
if necessary. If the same JDialog is created as non-modal,
the JPopupMenu is free to display outside the dialog as needed.
This appears to be a problem with medium-weight popup menus.
>2.Java SOURCE CODE that demonstrates the problem, if possible.
The following code produces a dialog with 16 buttons. Pressing
any button should cause a JPopupMenu to appear directly
beneath the button. Pressing buttons near the right and
bottom edges illustrates the problem (a clipped JPopupMenu)
Changing line 30 to:
MenuBug mb = new MenuBug(null, true);
makes the problem go away by making the dialog non-modal.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MenuBug extends JDialog {
public MenuBug(Frame frameOwner, boolean bModal) {
super(frameOwner, bModal);
JPanel panel = new JPanel(new GridLayout(4, 4));
panel.setLayout(new GridLayout(4, 4));
for (int i = 0; i < 16; i++) {
JButton button = new JButton("" + i);
button.addActionListener(new HandleButtonPress());
panel.add(button);
}
getContentPane().add(panel);
pack();
}
private class HandleButtonPress implements ActionListener {
public void actionPerformed(ActionEvent pAE) {
JPopupMenu pm = new JPopupMenu();
pm.add("This");
pm.add("is");
pm.add("a");
pm.add("test");
JButton button = (JButton)pAE.getSource();
pm.show(button, 0, button.getHeight());
}
}
public static void main(String[] strArgs) {
MenuBug mb = new MenuBug(null, true);
mb.setVisible(true);
}
}
>3.Exact text of any error message(s) that appeared.
>4.Any trace information.
N/A.
>5.The output of the commands "java -version" and "java -fullversion".
java version "1.2.1"
HotSpot VM (1.0fcs, mixed mode, build E)
java full version "JDK-1.2.1-A"
>6.Include additional configuration information that you think is relevant to the
> problem
> (e.g. the type of sound card for an audio problem).
None
(Review ID: 83914)
======================================================================
Here is a thorough test (menus, comboboxes, tooltips):
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class PopupTester {
public PopupTester(boolean lightweightsEnabled) {
JFrame f = new JFrame("Frame");
f.getContentPane().add(new PopupPanel(lightweightsEnabled), BorderLayout.CENTER);
f.pack();
f.show();
JDialog d = new JDialog(f, "Dialog", false);
d.getContentPane().add(new PopupPanel(lightweightsEnabled), BorderLayout.CENTER);
d.pack();
d.setLocation(200,0);
d.show();
d = new JDialog(f, "Modal Dialog", true);
d.getContentPane().add(new PopupPanel(lightweightsEnabled), BorderLayout.CENTER);
d.pack();
d.setLocation(400,0);
d.show();
}
public static void main(String[] args) {
boolean lightweightPopups = args.length > 0;
System.out.println("LightWeightPopups "+(lightweightPopups?"enabled":"disabled"));
PopupTester test = new PopupTester(lightweightPopups);
}
}
class PopupPanel extends JPanel {
String small[] = {"tiny"};
String medium[] = {"a","little","bigger"};
String big[] = {"a","really","really","really","super","duper",
"big","menu","for","testing","menus","and","how",
"they","behave","in","different","owner","windows"};
String smallTooltip = "!";
String mediumTooltip = "A little more info";
String bigTooltip = "<html>Wow, I can do html!<ul><li>one<li>two<li>three<li>four<li>five</ul></html>";
public PopupPanel(boolean lightWeightsEnabled) {
setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
int i;
JPopupMenu.setDefaultLightWeightPopupEnabled(lightWeightsEnabled);
JMenu smallMenu = new JMenu("Small");
for (i = 0; i < small.length; i++) {
smallMenu.add(small[i]);
}
smallMenu.setToolTipText(smallTooltip);
JMenu mediumMenu = new JMenu("Medium");
JMenu subMenu = new JMenu("More");
for (i = 0; i < medium.length; i++) {
mediumMenu.add(medium[i]);
subMenu.add(medium[i]);
}
mediumMenu.setToolTipText(mediumTooltip);
JMenu bigMenu = new JMenu("Big");
for (i = 0; i < big.length; i++) {
bigMenu.add(big[i]);
}
bigMenu.add(subMenu);
bigMenu.setToolTipText(bigTooltip);
JMenuBar menubar = new JMenuBar();
menubar.add(smallMenu);
menubar.add(mediumMenu);
menubar.add(bigMenu);
add(menubar);
JComboBox smallComboBox = new JComboBox(small);
add(smallComboBox);
JComboBox mediumComboBox = new JComboBox(medium);
add(mediumComboBox);
JComboBox bigComboBox = new JComboBox(big);
add(bigComboBox);
}
}
- duplicates
-
JDK-4178418 Swing in 1.2 should support heavyweight menus in modal dialogs
- Closed
-
JDK-4178531 Use new 1.2 APIs to allow PopupMenus for Modal Dialogs
- Closed