I'm using the below code to showing JDialog on taskbar and is perfectly working in JDK 1.6.
public class test8 {
public static void main(String[] args) {
Runnable r = new Runnable() {
public void run() {
JDialog d = new JDialog((Frame)null,Dialog.ModalityType.TOOLKIT_MODAL);
d.setTitle("title");
d.setSize(300,200);
d.setVisible(true);
System.exit(0);
}
};
EventQueue.invokeLater(r);
}
}
But When I'm setting the modality type using the method it's not working
public class test8 {
public static void main(String[] args) {
Runnable r = new Runnable() {
public void run() {
JDialog d = new JDialog();
d.setTitle("title");
d.setSize(300,200);
d.setModalityType(Dialog.ModalityType.TOOLKIT_MODAL);
d.setVisible(true);
System.exit(0);
}
};
EventQueue.invokeLater(r);
}
}
What is the difference betwwen the two codes ? Is there any way to solve this using the method ?
The problem is that certain constructors of JDialog
create a dummy frame owner if the owner is null
for historical reasons. But a Dialog
must not have an owner to be visible like a top-level window. I.e.
JDialog d=new JDialog((Window)null);
d.setModalityType(ModalityType.TOOLKIT_MODAL);
d.setVisible(true);
will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With