开发者

JDialog Close Icon Query?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜