在Windows任务栏上显示JDialog [英] Show JDialog on Windows taskbar

查看:425
本文介绍了在Windows任务栏上显示JDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Windows中显示 JDialog 。如何显示一个的JDialog (如的JFrame )我的Windows任务栏上?

I'm trying to display a JDialog in Windows. How do I show a JDialog (like JFrame) on my Windows taskbar?

推荐答案

对话框本身不能有任务栏条目,但您可以构造一个没有任何可见效果的框架,并将其用作对话框的父框架。然后它看起来像对话框有一个任务栏条目。以下代码显示了如何执行此操作:

A dialog itself cannot have a task bar entry, but you can construct a frame that does not have any visible effect and use it as a parent for the dialog. Then it will look like the dialog has a task bar entry. The following code shows you how to do it:

class MyDialog extends JDialog {

    private static final List<Image> ICONS = Arrays.asList(
            new ImageIcon("icon_16.png").getImage(), 
            new ImageIcon("icon_32.png").getImage(),
            new ImageIcon("icon_64.png").getImage());

    MyDialog() {
        super(new DummyFrame("Name on task bar", ICONS));
    }

    public void setVisible(boolean visible) {
        super.setVisible(visible);
        if (!visible) {
            ((DummyFrame)getParent()).dispose();
        }
    }
}

class DummyFrame extends JFrame {
    DummyFrame(String title, List<? extends Image> iconImages) {
        super(title);
        setUndecorated(true);
        setVisible(true);
        setLocationRelativeTo(null);
        setIconImages(iconImages);
    }
}

这篇关于在Windows任务栏上显示JDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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