How to notify the user of important events for a desktop application?

痞子三分冷 提交于 2019-12-04 12:57:34

Try using setAlwaysOnTop on your JFrame/JWindow.

With OS X the obvious answer would be to use Growl. But there exists a little project doing a similar service on windows environments. 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)?

Whichever you use, try to make it unfocusable(override isFocusable method) and call toFront.

Also let me know the result.

If you've got a budget, consider a license for JIDE. JIDE has an alert popup designed to look exactly like the outlook popup/alert widget.

l_39217_l

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)
    {
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!