JDK-4965240 : Support for "tap and hold" and other touch-oriented capabilities
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: other
  • CPU: unknown
  • Submitted: 2003-12-08
  • Updated: 2018-09-05
Related Reports
Relates :  
Relates :  
There has been interest from J2ME (PP) in having support for touch-oriented 
capabilities in J2SE.  I'll put a couple of email threads in the Comments.  
A snippet is below.  

> A prime example (we can likely generate more)
> is that in PDAs and similar devices without  
> a keyboard, users can't access a popup menu  
> on an object the way they might on a desktop 
> using the nth mouse button or key+mouse button.
> Pocket PC apps (and Qt on Zaurus) support
> a "tap and hold" capability where when users
> touch and hold, they can popup a menu.

EVALUATION I assume that MouseEvent are implemented similary under pen-based systems as they are with mouse-based systems, within reason. For instance, I would expect to receive: - a MOUSE_PRESSED when the stylus hits the touchscreen - a MOUSE_RELEASED when the stylus leaves the touchscreen - a MOUSE_DRAGGED events while the stylus is being moved while in contact with the touchscreen (for performing actions such as writing) The difference between a tap and a tap-and-hold is the time between the MOUSE_PRESSED and MOUSE_RELEASED events. In fact, it's not too hard to do something when sufficient times has passed after a MOUSE_PRESSED using the current API. The following test shows a PopupMenu when the mouse button is held down for some period of time, yet still retains normal click and drag functionality. // Test of using current APIs to implement "tap-and-hold" functionality import java.awt.*; import java.awt.event.*; import javax.swing.Timer; public class Test extends Frame implements MouseListener, MouseMotionListener, ActionListener { private static int DELAY = 500; private boolean tapAndHold = false; private Point tapLoc; PopupMenu menu; Timer timer; public Test() { super("Test"); addMouseListener(this); addMouseMotionListener(this); setBounds(100, 100, 200, 200); menu = new PopupMenu("Popup Menu"); menu.add("Menu Item"); menu.add("Menu Item"); add(menu); timer = new Timer(DELAY, this); } public static void main(String[] args) { Test t = new Test(); t.setVisible(true); } public void mousePressed(MouseEvent e) { tapAndHold = true; tapLoc = e.getPoint(); timer.start(); } public void mouseReleased(MouseEvent e) { tapAndHold = false; timer.stop(); } public void actionPerformed(ActionEvent e) { if (tapAndHold) { menu.show(this, tapLoc.x, tapLoc.y); } timer.stop(); } public void mouseDragged(MouseEvent e) { tapAndHold = false; timer.stop(); } public void mouseMoved(MouseEvent e) {} public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} } ###@###.### 2003-12-08