Hide window from taskbar

I am trying to develop my own application for posting notes on the desktop (similar to Sticky Notes under Windows). Everything works fine, but I still run into a problem: since I want the application to be as "minimal" as possible, I would like it to not appear on the taskbar so that it does not bother the user. In the end, I would like it to appear in the system tray, but at the moment this is not the main thing. To make the application cross-platform, I develop it in Java, and I read that in order to prevent it from appearing in the taskbar, you could use JDialog. Now my class

public class NoteWindow extends JDialog implements WindowListener, WindowFocusListener, KeyListener, ComponentListener,
        MouseMotionListener, MouseListener

and in the code I also put

setType(Type.UTILITY);
setBounds(100, 100, 235, 235);
getContentPane().setLayout(null);
setUndecorated(true);

but it doesn't seem to work: under Linux Mint 17.2, I still see windows (every window corresponding to a note) on the taskbar (or its equivalent on Linux).

Did I miss something?

EDIT

I place the image to show what I mean, and that I would not want to see:

screenshot

+4
source share
1 answer

JDialogmust be attached to the parent JFrame. Then in the dialog box there will be no corresponding button on the taskbar. Therefore, I suggest creating an instance JFramebut not making it visible . In the Sticky Notes example, each note window will have the same parent element.

package com.thomaskuenneth;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class DialogDemo {

    public static void main(String[] args) {
        JFrame parent = new JFrame();
        JDialog d = new JDialog(parent, "Hello");
        d.setBounds(50, 50, 200, 200);
        d.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        d.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        d.setVisible(true);
    }
}

, setUndecorated(true); . , , , , , setUndecorated(true); ,

0

Source: https://habr.com/ru/post/1608373/


All Articles