JDK-4119064 : isPopupTrigger never returns true on Windows
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.1.5,1.1.6,1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_95,windows_nt
  • CPU: x86
  • Submitted: 1998-03-12
  • Updated: 1998-03-12
  • Resolved: 1998-03-12
Related Reports
Relates :  
Description

Name: rm29839			Date: 03/12/98


The isPopupTrigger bug is still present in
Windows (see bug 4070464).

Run the following code using Swing 1.0 upwards and
1.1.5 or 1.2beta2 and the popupmenu will never be
displayed since on Windows NT (I've not tried 95)
isPopupTrigger is never! true in mousePressed()
only mouseReleased()

This code is from george saab of the swing team

import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
// use this one if we are using 1.2
//import java.awt.swing.*;

class t2 extends JFrame {
public void init() {
final JPopupMenu m = new JPopupMenu();
m.add(new JMenuItem("Wombat"));
m.add(new JMenuItem("Sussex"));
m.add(new JMenuItem("Kizumbo"));
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if (e.isPopupTrigger() == true) {
m.show(e.getComponent(), e.getX(), e.getY());
}
}
});
}

public static void main(String[] args) {
t2 test = new t2();
test.init();
test.setSize(200,100);
test.setTitle("Popup Menu Example");
test.show();
}
}
 
This code works fine under Solaris and HPUX but
not NT. This is a bug and 4070464 should not of
been closed...
(Review ID: 26120)
======================================================================

Comments
WORK AROUND Name: rm29839 Date: 03/12/98 There is a workaround, but it's nasty since . it works on NT, but not under Solaris/HPUX . it does not provided 100% desired functionality Basically the isPopupTrigger does return true in the mouseReleased() method, not mousePressed() bad bad bad, this code works on NT, not UNIX import java.awt.*; import java.awt.event.*; import com.sun.java.swing.*; // use this one if we are using 1.2 //import java.awt.swing.*; class t2 extends JFrame { public void init() { final JPopupMenu m = new JPopupMenu(); m.add(new JMenuItem("Wombat")); m.add(new JMenuItem("Sussex")); m.add(new JMenuItem("Kizumbo")); addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger() == true) { m.show(e.getComponent(), e.getX(), e.getY()); } }}); } public static void main(String[] args) { t2 test = new t2(); test.init(); test.setSize(200,100); test.setTitle("Popup Menu Example"); test.show(); } } Ta Da. Popup's under NT and I thought it would never happen. Seriously though we need to get this one closed properly this time. ======================================================================
11-06-2004

EVALUATION The whole reason for having isPopupTrigger is to allow a single AWT app to work within the recommended User Interface guidelines for popup menus on different windowing systems. On Windows systems, the convention is to popup a menu on mouse release, while on Solaris it's on mouse down -- picking either one as the AWT "default" breaks platform integration, thereby making AWT apps less UI-compliant than native apps. This API therefore works as designed, and any AWT app using it *must* check both mousePressed and thomas.ball@Eng 1998-03-12 It has been a common mistake made by a lot of people including myself to check for isPopupTrigger() in either mousePressed or mouseReleased and not both. One can argue that the programmer was stupid and should do the right thing, however if many people are doing the same mistake (as indicated by the code in the original bug and code in the corkaround) may be it should implemented in a different way. Here goes ... May be a new Event type PopupMenuTriggerEvent needs to be created and the Component class fires it in its processMouseEvent() method. This will ofcourse require public void addPopupMenuTriggerListener(PopupMenuTriggerListener pmtl); public void removePopupMenuTriggerListener(PopupMenuTriggerListener pmtl); and corresponding PopupMenuTriggerListener class. I know ... I know ... I will file an RFE also. sandip.chitale@Eng 1998-04-07
07-04-1998