从任务栏隐藏窗口 [英] Hide window from task bar

查看:35
本文介绍了从任务栏隐藏窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发自己的应用程序,用于在桌面上放置笔记(类似于 Windows 操作系统下的便笺).一切正常,但我仍然面临一个问题:因为我希望应用程序尽可能最小"尽可能地,我希望它不要出现在任务栏中,以免打扰用户.最终,我希望它出现在系统托盘中,但目前,这不是重点.为了使应用程序跨平台,我正在用 Java 开发它,并且我读到它是为了不让它出现在可以使用 JDialog 的任务栏中.现在我的班级是

I'm trying to develop my own application for placing notes on the desktop (similar to Sticky Notes under Windows OS). Everything is working nicely but I am still facing a problem: since I want the application to be as "minimal" as possible, I would like it not to appear in the taskbar, so that it doesn't bother the user. Eventually, I would like it to appear in the system tray but, for the moment, this is not the point. To make the application cross-platform, I am developing it in Java, and I read that in order not to make it appear in the taskbar one could use a JDialog. Now my class is

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

在代码中我也放了

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

但它似乎不起作用:在 Linux Mint 17.2 下,我仍然看到任务栏中的窗口(每个窗口对应一个注释)(或 Linux 下的等效项).

but it doesn't seem to be working: under Linux Mint 17.2 I still see the windows (each window corresponding to a note) in the taskbar (or its equivalent under Linux).

我错过了什么吗?

我发布了一张图片来展示我的意思,以及我不想看到的内容:

I post an image to show what I mean, and what I would like not to see:

推荐答案

JDialog 应该附加到 JFrame 父级.那么对话框在任务栏中将没有相应的按钮.所以,我建议创建一个 JFrame 实例,但不要让它可见.在粘滞便笺示例中,每个便笺窗口都具有相同的父级.

A JDialog should be attached to a JFrame parent. Then the dialog will not have a corresponding button in the taskbar. So, I suggest creating a JFrame instance but not making it visible. In the Sticky Notes example, each note window would have the same parent.

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

Please note that I did not use setUndecorated(true); to be able to respond to closing the window. If you have other means to respond on such requests, for example by clicking on a button inside the dialog, you can of course use setUndecorated(true);.

这篇关于从任务栏隐藏窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆