首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有任务栏图标的JFrame弹出窗口

没有任务栏图标的JFrame弹出窗口
EN

Stack Overflow用户
提问于 2013-04-27 23:52:58
回答 1查看 2K关注 0票数 2

我创建了从JFrame继承的通知窗口,但它们在windows任务栏中显示为新图标。是否可以在通知出现时突出显示主应用程序图标(例如在skype中,当新消息到来时),而不在通知窗口的任务栏中显示新图标?

以下是弹出窗口的代码:

代码语言:javascript
复制
public class NotificationWindow extends JFrame
{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    static private int m_count = 0;

    public NotificationWindow(String text)
    {
        super("NotificationWindow");
        setLayout(new GridBagLayout());

        setSize(300, 70);
        setLocationRelativeTo(null);

        setOpacity(0.77f);
        setUndecorated(true);
        setResizable(false);

        add(new JLabel(text));

        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent evt)
            {
                --m_count;
            }
        });

        ++m_count;
    }

    static public int GetWindowCount()
    {
        return m_count;
    }

    static public void ShowNotificationWindow(final String text)
    {
        // Determine if the GraphicsDevice supports translucency.
        GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment
                .getLocalGraphicsEnvironment();
        final GraphicsDevice graphicsDevice = graphicsEnvironment
                .getDefaultScreenDevice();

        // If translucent windows aren't supported, exit.
        if (!graphicsDevice.isWindowTranslucencySupported(TRANSLUCENT))
        {
            System.err.println("Translucency is not supported");
            System.exit(0);
        }

        JFrame.setDefaultLookAndFeelDecorated(true);

        // Create the GUI on the event-dispatching thread
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run()
            {
                NotificationWindow notificationWindow = new NotificationWindow(
                        text);

                Insets scnMax = Toolkit.getDefaultToolkit().getScreenInsets(
                        notificationWindow.getGraphicsConfiguration());
                int taskBarSize = scnMax.bottom;
                Rectangle rect = graphicsDevice.getDefaultConfiguration()
                        .getBounds();
                int x = (int) rect.getMaxX() - notificationWindow.getWidth();
                int y = (int) rect.getMaxY() - notificationWindow.getHeight()
                        - taskBarSize - ((m_count - 1) % 7)
                        * notificationWindow.getHeight();
                notificationWindow.setLocation(x, y);
                notificationWindow.setVisible(true);
            }
        });
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-27 23:56:28

不要扩展JFrame,而要扩展JDialog

一般来说,任何应用程序都应该只有一个JFrame。其他子窗口应为JDialogs。请参阅:The Use of Multiple JFrames: Good or Bad Practice?

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16254063

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档