Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why no default close button in JDialog

 
Yan Zhou
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a JFrame instead ?
 
Pat Hays
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}

}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic