aspose file tools
The moose likes Swing / AWT / SWT and the fly likes why no default close button in JDialog Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "why no default close button in JDialog" Watch "why no default close button in JDialog" New topic
Author

why no default close button in JDialog

Yan Zhou
Ranch Hand

Joined: Sep 02, 2003
Posts: 136
Hi,

I create a JDialog passing in an existing parent JFrame at its constructor. However,

1) my dialog has no default close button like a frame has
2) when my dialog starts up, it does not show up in Task bar as a frame would.

How could I make them happen?
Thanks.
Yan
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
Use a JFrame instead ?
Pat Hays
Ranch Hand

Joined: Aug 20, 2004
Posts: 138
Hellow Yan,

you could still use your JDialog, but you need use Windows Looking and Feel instead. The following code works.

----------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TestDialog
{
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch (Exception ex)
{
System.out.println("Failed loading L&F: ");
System.out.println(ex);
}

final JFrame w = new JFrame("Owner Window");
JButton btn = new JButton("Show Dialog");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
JDialog d = new JDialog(w);
d.setSize(200,100);
d.setVisible(true);
}});
JPanel p = new JPanel();
p.add(btn);
w.getContentPane().add(p);
w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
w.setSize(500,360);
w.setLocation(100,36);
w.setVisible(true);
}

}


Download Java GUI Builder, <a href="http://www.mars3000.com" target="_blank" rel="nofollow">http://www.mars3000.com</a>
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: why no default close button in JDialog
 
Similar Threads
JDialog question
gui and thread
Modal JDialog
Closing a dialog in Swing?
Minimize button in JFrame