本文介绍了Java:Flash一个窗口来吸引用户的注意力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有更好的方法在Java中使用Flash来闪存:

Is there a better way to flash a window in Java than this:

public static void flashWindow(JFrame frame) throws InterruptedException {
        int sleepTime = 50;
        frame.setVisible(false);
        Thread.sleep(sleepTime);
        frame.setVisible(true);
        Thread.sleep(sleepTime);
        frame.setVisible(false);
        Thread.sleep(sleepTime);
        frame.setVisible(true);
        Thread.sleep(sleepTime);
        frame.setVisible(false);
        Thread.sleep(sleepTime);
        frame.setVisible(true);
}

我知道这段代码很吓人......但是它可以正常工作。 (我应该实现一个循环......)

I know that this code is scary...But it works alright. (I should implement a loop...)

推荐答案

有两种常用方法可以做到这一点:使用JNI设置紧急提示在任务栏的窗口中,创建一个通知图标/消息。我更喜欢第二种方式,因为它是跨平台的并且不那么烦人。

There are two common ways to do this: use JNI to set urgency hints on the taskbar's window, and create a notification icon/message. I prefer the second way, since it's cross-platform and less annoying.

参见,特别是 method。

See documentation on the TrayIcon class, particularly the displayMessage() method.

以下链接可能是兴趣:

这篇关于Java:Flash一个窗口来吸引用户的注意力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!