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();
}
});
}
}
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.