简体   繁体   English

如何通知用户桌面应用程序的重要事件?

[英]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.也让我知道结果。

If you've got a budget, consider a license for JIDE .如果您有预算,请考虑获得JIDE的许可证。 JIDE has an alert popup designed to look exactly like the outlook popup/alert widget. JIDE 有一个警报弹出窗口,其设计看起来与 outlook 弹出/警报小部件完全相同。

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.

相关问题 如何使JIRA通知Java应用程序有关事件? - How do I make JIRA notify a Java application about events? 每当我向远程数据库添加内容时如何通知应用程序用户? - How to notify application user whenever i add something to remote database? 用户登录桌面应用程序时如何隐藏登录/注册表格? - How to hide login/register form when user is logged in desktop application? 如何创建在用户登录后启动的桌面应用程序? - How to create a Desktop Application which starts after user logged in? 如何从Java桌面应用程序保留fos_user数据 - how to persist fos_user data from java desktop application 如何在JavaFX Desktop Application中登录后保留用户信息 - How to keep user information after login in JavaFX Desktop Application java 桌面应用程序中的用户 Session - User Session in java desktop application 如何通知Java桌面客户端有关服务器更改的信息? - how to notify java desktop clients about changes from server? 如何通知其他团队成员重要的项目变更(使用SVN或Ant)? - How to notify other team members about important project changes (using SVN or Ant)? 如何在多线程应用程序中通知特定线程 - How to notify a specific thread in a multithread application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM