[英]How to notify the user of important events for a desktop application?
Our customer is using our software (Java Swing application started using Webstart) besides other software like MS Office, to do his job.除了 MS Office 等其他软件外,我们的客户还使用我们的软件(Java Swing 应用程序开始使用 Webstart)来完成他的工作。 From time to time there are important events he has to deal with in our software without much delay.
有时,他必须毫不拖延地在我们的软件中处理重要事件。 The customer wants to have a prominent notification then.
客户希望有一个突出的通知。 Now he might be using Excel at the moment, so popping up a message box will not suffice (although the entry in the task bar will be flashing).
现在他可能正在使用 Excel,所以弹出一个消息框是不够的(尽管任务栏中的条目会闪烁)。
We need some mechanism like the Outlook notifier, ie a popup that is always visible but does not steal the focus.我们需要一些机制,例如 Outlook 通知程序,即始终可见但不会窃取焦点的弹出窗口。 The notifier should be displayed all the time until the reason for the message has gone (the user has solved the issue) or the user has closed the message (like in outlook).
通知程序应一直显示,直到消息的原因消失(用户已解决问题)或用户已关闭消息(如在 Outlook 中)。 Additionally we want to display a tray icon and maybe play a sound.
此外,我们希望显示一个托盘图标并可能播放声音。
I've tried the Java6 java.awt.SystemTray as well as the JDIC (version 0.9 since we already have that lib in the classpath of that project) equivalent, but I did not find a way to set the timeout of the TrayIcon.displayMessage method, and the message seems not to be always on top.我已经尝试过 Java6 java.awt.SystemTray 以及 JDIC(版本 0.9,因为我们已经在该项目的类路径中拥有该库)等效,但我没有找到设置 TrayIcon.displayMessage 超时的方法方法,并且消息似乎并不总是最重要的。
Is there any other option besides JNI to achieve the requested behavior?除了 JNI 之外,还有其他选择来实现所请求的行为吗?
If JNI is the only choice and since Windows is the only platform of our customers, is the Outlook notifier an Outlook only feature, or is it freely usable through the Windows API? If JNI is the only choice and since Windows is the only platform of our customers, is the Outlook notifier an Outlook only feature, or is it freely usable through the Windows API?
Or what other options exist to notify the user about an important task to perform in one software without hindering him to complete his current task in another software.或者还有哪些其他选项可以通知用户要在一个软件中执行的重要任务,而不会妨碍他在另一个软件中完成当前任务。 A system modal dialog therefore is no option!
因此,系统模式对话框是没有选择的!
Try using setAlwaysOnTop on your JFrame/JWindow.尝试在您的 JFrame/JWindow 上使用setAlwaysOnTop 。
With OS X the obvious answer would be to use Growl .对于 OS X,显而易见的答案是使用Growl 。 But there exists a little project doing a similar service on windows environments.
但是有一个小项目在 windows 环境中提供类似的服务。 It's called Snarl .
它被称为咆哮。 This might give you a new option to try.
这可能会给你一个新的尝试选择。
Drawback: You'll have to install a tool on the client's machines.缺点:您必须在客户端的机器上安装一个工具。 From your description I assume you have a defined group of users on company workplaces, right?
根据您的描述,我假设您在公司工作场所有一组已定义的用户,对吧? So this might acceptable, nevertheless.
因此,尽管如此,这可能是可以接受的。
Using Tray: Which component are you using to show message (JPopup, JDialog, JFrame, JWindow)?使用托盘:您使用哪个组件来显示消息(JPopup、JDialog、JFrame、JWindow)?
Whichever you use, try to make it unfocusable(override isFocusable
method) and call toFront
.无论您使用哪种方式,请尝试使其无法聚焦(覆盖
isFocusable
方法)并调用toFront
。
Also let me know the result.也让我知道结果。
Here is an example:这是一个例子:
class AlertWindow extends Window implements MouseListener
{
AlertWindow(JFrame frame)
{
super(frame);
this.setAlwaysOnTop(true);
this.setFocusable(false);
this.setSize(200, 200);
this.setLocation(500, 0);
this.setBackground(Color.BLACK);
addMouseListener(this);
try {
Class<?> awtUtilitiesClass = Class.forName("com.sun.awt.AWTUtilities");
Method mSetWindowOpacity = awtUtilitiesClass.getMethod("setWindowOpacity", Window.class, float.class);
mSetWindowOpacity.invoke(null, this, Float.valueOf(0.50f));
} catch (NoSuchMethodException ex) {
ex.printStackTrace();
} catch (SecurityException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (IllegalAccessException ex) {
ex.printStackTrace();
} catch (IllegalArgumentException ex) {
ex.printStackTrace();
} catch (InvocationTargetException ex) {
ex.printStackTrace();
}
}
public void mouseClicked(MouseEvent e)
{
this.setVisible(false);
}
public void mousePressed(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.