开发者

JDialog Close Icon Query?

开发者 https://www.devze.com 2023-03-18 18:42 出处:网络
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

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.


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


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.


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.
    }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号