I am creating a application for window and mac. I am displaying a Dialog Box on frame. Its working fine on window but I am facing problem regarding movement of dialog on mac. When I move frame, dialog box move relative to frame . I need static dialog similar to windows dialog. I have searched a lot but didn't get a solution. Code is following
public class Parent extends JFrame{
public Parent() {
setVisible(true);
setSize(200,200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
new Child(this);
}
public static void main(String[] args)
throws InvocationTargetException, InterruptedException{
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
new Parent();
}
});
}
class Child extends JDialog{
public Child(Parent parent) {
super(parent);
setType(JFrame.Type.UTILITY);
setVisible(true);
setSize(100, 100);
}
}
}
This is a known bug in the JDK listed at: https://bugs.openjdk.java.net/browse/JDK-7199846.
Unfortunately the only workaround listed is to pass null
to the JDialog
constructor.
Example:
class Child extends JDialog {
public Child(Parent parent) {
super((JFrame)null);
setType(JFrame.Type.UTILITY);
setVisible(true);
setSize(100, 100);
}
}