1

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);

        }
    }
}
msrd0
  • 7,816
  • 9
  • 47
  • 82

1 Answers1

2

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);
        }
}
Benjamin Albert
  • 738
  • 1
  • 7
  • 19
  • No its not working. I need dialog box must be always above on frame. It's alwaysOnTop(true) property should not be false when I click frame. – Rajni Kant Sharma Oct 12 '14 at 07:54
  • @RajniKantSharma What do you mean by "It's alwaysOnTop(true) property should not be false when I click frame", do you want the `Dialog` to always be in focus?, because I don't see `setAlwaysOnTop(true);` anywhere in your code. – Benjamin Albert Oct 12 '14 at 08:02
  • Yes I want Dialog to always be in focus. by `super(parent);` I am getting this feature. I want Dialog box should be always above on frame i.e. I can interact with frame while Dialog box is visible. – Rajni Kant Sharma Oct 12 '14 at 08:16
  • You might want to take a look at: https://bugs.openjdk.java.net/browse/JDK-7199846?page=com.atlassian.streams.streams-jira-plugin:activity-stream-issue-tab. Unfortunately the only workaround listed is my solution – Benjamin Albert Oct 12 '14 at 08:38