IKM2007
IKM2007

Reputation: 726

JFrame popup without taskbar icon

I created notification windows inherited from JFrame, but they appear with new icon in Windows taskbar. Is it possible to highlight main application icon when notification appears(such as in skype, when new message come) and do not show new icon in taskbar for notification window?

Here is code for popup:

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);
            }
        });
    }
}

Upvotes: 2

Views: 2113

Answers (1)

camickr
camickr

Reputation: 324207

Don't extend a JFrame, instead extend a JDialog

In general, any application should only have a single JFrame. Other child windows should be JDialogs. See: The Use of Multiple JFrames: Good or Bad Practice?

Upvotes: 5

Related Questions