how to disable (X) button on top of dialog.

hi i am working with dialog and i have to put two option on dialog yes/nobut cross(X) button is coming default at top of dialog, can i diable that anyway. is that possible or not?Thnx
[211 byte] By [Prashant_SDNa] at [2007-11-27 7:57:51]
# 1
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);note: not tested.
j_shadinataa at 2007-7-12 19:39:44 > top of Java-index,Desktop,Core GUI APIs...
# 2
that is not problem to do nothing with button but even i don't want this button on the top. this what i am trying to do, is that possible to do?any thoughts!!!!!!!
Prashant_SDNa at 2007-7-12 19:39:44 > top of Java-index,Desktop,Core GUI APIs...
# 3
I was also looking for this this post helped me http://forum.java.sun.com/thread.jspa?threadID=481316&messageID=2246252
Mumeia at 2007-7-12 19:39:44 > top of Java-index,Desktop,Core GUI APIs...
# 4
have you done this please share your doing with us.ThnX
Prashant_SDNa at 2007-7-12 19:39:44 > top of Java-index,Desktop,Core GUI APIs...
# 5
if you are using thisJDialog.setDefaultLookAndFeelDecorated(true);you can iterate the dialog's components and remove the 'X' button
Michael_Dunna at 2007-7-12 19:39:44 > top of Java-index,Desktop,Core GUI APIs...
# 6
will you show me something else becaue i want to remove default button (X), how can tha possible.looking for your response.
Prashant_SDNa at 2007-7-12 19:39:44 > top of Java-index,Desktop,Core GUI APIs...
# 7

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

class Testing

{

public void buildGUI()

{

JDialog.setDefaultLookAndFeelDecorated(true);

JDialog d = new JDialog();

d.setModal(true);

removeX(d);

JPanel p = new JPanel(new GridBagLayout());

JButton btn = new JButton("Exit");

p.add(btn,new GridBagConstraints());

d.getContentPane().add(p);

d.setSize(400,300);

d.setLocationRelativeTo(null);

btn.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent ae){

System.exit(0);

}

});

d.setVisible(true);

}

public void removeX(Component comp)

{

if (comp instanceof AbstractButton)

{

comp.getParent().remove(comp);

}

if (comp instanceof Container)

{

Component[] comps = ((Container)comp).getComponents();

for(int x = 0, y = comps.length; x < y; x++)

{

removeX(comps[x]);

}

}

}

public static void main(String[] args)

{

SwingUtilities.invokeLater(new Runnable(){

public void run(){

new Testing().buildGUI();

}

});

}

}

Michael_Dunna at 2007-7-12 19:39:44 > top of Java-index,Desktop,Core GUI APIs...
# 8

Thanks a lot Michael. with this code we are able to remove (X) button but

that should be set setDefaultLookAndFeelDecorated(true);

whereas i am working with different look and feel so this idea will not work properly with my case.

thanks a lot again.

Prashant_SDNa at 2007-7-12 19:39:44 > top of Java-index,Desktop,Core GUI APIs...