目前在我的(JRuby代码)中,我希望以不同于“双击托盘图标”(awt.TrayIcon实例)的方式处理“气球关闭”消息:
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"和java https://gist.github.com/4338167中的等效代码。
当1)用户双击系统托盘中的图标,或者2)用户通过单击气球关闭托盘的最近气球消息(而不是在x上)时,此操作侦听器似乎会被调用。
有没有可能区分这两种不同的事件类型(两者似乎都有事件id 1001),或者我必须仅仅通过时间相关或其他什么来推断它?或者,我是否能以某种方式“知道”气球仍然在上升,因此点击肯定来自它?
发布于 2012-12-20 03:32:29
TrayIcon的文档似乎暗示,单击气球消息可以触发ActionEvent,对于您来说,这与双击图标本身是相同的。
你可能需要添加一个鼠标监听器来在点击时触发,如果点击事件后紧跟着一个小周期内的ActionEvent,那么它就是双击,否则就是对正在显示的消息的点击。通过选择一个足够小的间隔,您应该能够正确地区分它们。
https://stackoverflow.com/questions/13947205
复制相似问题