JDialog不显示最小/关闭按钮 [英] JDialog not showing minimize/close button

查看:161
本文介绍了JDialog不显示最小/关闭按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

研究问题时,似乎大多数人都想做相反的事情(即删除最小化/关闭"按钮). 使用反复出现的setUndecoratedsetDefaultCloseOperation

When researching the problem, it seems most people are wanting to do the opposite (i.e remove the minimize/close button). I've had no success using the reoccurrent setUndecorated and setDefaultCloseOperation

这是我的代码:

private class TestDialog extends JDialog 
{
    public static final String title_ = "Test Dialog";

    public TestDialog(JFrame parent)
    {
        super(parent,title_,true);
        setMinimumSize(new Dimension(500,500));
        setLocationRelativeTo(null);
        setUndecorated(false);
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    }
}

显示对话框时,我得到以下信息:

When I display the dialog I get the following:

其他信息:
操作系统:Ubuntu
Java版本:1.7.0_55

Other info:
OS: Ubuntu
Java version: 1.7.0_55

推荐答案

目前尚不清楚问题可能出在哪里,但是下面的完整示例可在Ubuntu 12,Java 6上运行;它可以帮助您确定问题所在.请注意, all 顶级容器事件分配线程上构建.

It's not clear where things may have gone awry, but the complete example below works on Ubuntu 12, Java 6; it may help you pin down the problem. Note that all top-level containers must be constructed on the event dispatch thread.

import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;


public class TestDialog extends JDialog {

    public static final String title = "Test Dialog";

    public TestDialog(JFrame parent) {
        super(parent, title, true);
        add(new JPanel(){

            @Override
            public Dimension getPreferredSize() {
                return new Dimension(320, 240);
            }
        });
        pack();
        setLocationRelativeTo(null);
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    }
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new TestDialog(null).setVisible(true);
            }
        });
    }
}

这篇关于JDialog不显示最小/关闭按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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