JDialog关闭图标查询?

发布于 2024-11-19 05:55:22 字数 110 浏览 3 评论 0原文

我想删除 JDialog 选项中存在的关闭图标。我怎样才能实现这一目标?

要求:尝试通过删除“x”或关闭图标来重新设计默认对话框结构,

提前谢谢您。

I would like remove the close icon present in the JDialog Option. How can I Achieve this?

Requirement: Trying to re-design the default Dialog Structure by removing the 'x' or close icon

Thank You in Advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我三岁 2024-11-26 05:55:22

您无法删除它(并保留标题栏),但您可以使用以下方法禁用其功能:

dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);

You can't remove it (and keep the title bar) but you can disable its functionality by using:

dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
柠檬 2024-11-26 05:55:22

dialog.setUndecorated(true); 应该为您执行此操作(从 java.awt.Dialog 类),但有一些问题,最值得注意的是此方法也会删除标题栏,使得对话框无法在屏幕上移动。

此问题/答案了解更多信息。

dialog.setUndecorated(true); should do it for you (a method inherited from the java.awt.Dialog class), but there are some catches, most notably that this method will also remove the title bar, making it impossible to move the dialog around the screen.

This this question/answer for more information.

若水微香 2024-11-26 05:55:22

如果您想要执行一些额外的操作,那么总是最好重写 setDefaultCloseOperation 方法。然而你无法阻止对话框关闭。我尝试过,但无法阻止它关闭。但是,是的,通过覆盖 setDefaultcloseoperation 方法,我能够执行一些列表清理和文件关闭操作。
尝试按如下方式重写该函数。

public class LaunchGenerator extends JDialog 
{
public LaunchGenerator()
{
this.setSize(1200, 900);
        contentPanel =new JPanel();
        contentPanel.setLayout(null);
        this.setContentPane(contentPanel);
        setDefaultCloseOperation(2); // you can write anything inside the function.
}

public void setDefaultCloseOperation(int i)
{
    if(i==2)
    {
        dispose();
                     //and all other things that you want to do. such as file      closing     and list cleanups.etc ,etc.
    }

}

IT is always beeter to override the setDefaultCloseOperation method if you want to perform some extra operations. How ever you can not stop the dialog from getting closed. I tried but was not able to stop it from closing. But yes by overiding the setDefaultcloseoperation method i was able to perform some list cleanup and file closing operations.
Try to override the function as follows.

public class LaunchGenerator extends JDialog 
{
public LaunchGenerator()
{
this.setSize(1200, 900);
        contentPanel =new JPanel();
        contentPanel.setLayout(null);
        this.setContentPane(contentPanel);
        setDefaultCloseOperation(2); // you can write anything inside the function.
}

public void setDefaultCloseOperation(int i)
{
    if(i==2)
    {
        dispose();
                     //and all other things that you want to do. such as file      closing     and list cleanups.etc ,etc.
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文