1

Currently in my (JRuby code), I want to handle "balloon close" messages differently than "double click on the tray icon" (awt.TrayIcon instance):

import java.awt.TrayIcon
import java.awt.event.MouseListener

tray = java.awt.SystemTray::system_tray
image = java.awt.Toolkit::default_toolkit.get_image('')

trayIcon = TrayIcon.new(image, 'name', nil)

tray.add(trayIcon)
trayIcon.addActionListener do |evt|
  puts "in here", evt.id
end
trayIcon.displayMessage("title", "try clicking within the baloon, but not the x, then double clicking the tray icon", TrayIcon::MessageType::INFO)
puts "try clicking within the balloon message, or double clicking, both seem to generate the same event"

and the equivalent code in java https://gist.github.com/4338167

it seems that this action listener gets called either when 1) a user double clicks the icon in the system tray, or 2) a user closes a tray's recent balloon message by clicking on the balloon (not on the x).

Is it possible to distinguish between the 2 different event types (both seem to have event id 1001), or must I just infer it by timing relative or something else? Or can I somehow "know" that the balloon is still up, and thus the click must have come from it?

mKorbel
  • 108,320
  • 17
  • 126
  • 296
rogerdpack
  • 50,731
  • 31
  • 212
  • 332
  • please I lost in Ruby, are we talking about [How to Use the System Tray](http://docs.oracle.com/javase/tutorial/uiswing/misc/systemtray.html), or post an SSCCE, no issue to determine double click or mouseevents to Message, a few times I'm answered for AWT / Swing – mKorbel Dec 19 '12 at 07:17
  • ok added jruby and java example (and yes). My question is not how to determine double click, but more how to determine when a balloon is closed *versus* a double click, both seem to send the same message... – rogerdpack Dec 19 '12 at 16:47
  • [have to convert to JRuby](http://stackoverflow.com/a/8460383/714968), or [another here](http://stackoverflow.com/a/6290045/714968) – mKorbel Dec 19 '12 at 19:04

1 Answers1

3

The documentation for TrayIcon seems to imply that clicking on the balloon message can trigger an ActionEvent, which is the same as, for your case, double-clicking on the icon itself.

You may need to add a mouse listener to trigger on clicks, and if a click event is followed by an ActionEvent within some small period then it's a double-click, otherwise it's a click on the message being displayed. By choosing a sufficiently small interval, you should be able to properly distinguish them.

Petesh
  • 82,900
  • 3
  • 91
  • 111
  • Yeah I figured something like this might be necessary...trying to "time" how long it has taken since the last click occurred, etc...thanks! – rogerdpack Dec 19 '12 at 23:24
  • I had the same question (in a Java program), and noticed that empirically, the click on the balloon is accompanied by the 1024 bit being on in the event's modifiers field. But I don't know what to make of it -- 1024 = TEXT_EVENT_MASK, which doesn't make much sense. But I also noticed that Shift and other modifiers show up differently than documented (e.g., Shift should be value of SHIFT_MASK (1), but it appears as 64). – vanmelle Mar 08 '13 at 23:01