Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8136051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:37:20+00:00 2026-06-06T10:37:20+00:00

I have a modal settings dialog which is a JDialog. In this settings window

  • 0

I have a modal settings dialog which is a JDialog. In this settings window I placed some components including a button to yet another modal settings dialog which is also a JDialog. I made them JDialogs because that is the only way I know of to make a modal dialog.

The problem is this: when I create the main settings dialog I have to construct the JDialog either without a parent Frame or with a parent Frame. Since my main window is a JFrame, I can just pass that to the main settings dialog constructor. But when I want to create the second modal settings dialog which should have the main settings dialog as a parent, I can’t find a way to get the (J)Frame of the JDialog. I do want to pass that main settings dialog as a parent so that the second settings dialog centers on it when it is shown. Let’s assume the second settings dialog has no constructor for passing a location, just the constructors of the JDialog.

Is there a way to get the (J)Frame of a JDialog?
Is there a design flaw in my setup and should I have used something else for these settings dialogs? (And if so, how should I make these alternative settings dialogs modal?)

Thank you for your help,
Erik

UPDATE:
Thank you all for your answers. They led me to understand that apparently it’s not absolutely necessary to have an owner for a JDialog. I thought this was needed for the dialog to be able to disable the owner until the dialog is closed, but apparently the modality is independent of the owner. I also noticed that even with an owner the dialog still doesn’t center on the owner, so now my code is like:

public class CustomDialog extends JDialog {
    public CustomDialog(String title) {
        setModal(true);
        setResizable(false);
        setTitle(title);

        buildGUI();
    }

    public Result showDialog(Window parent) {
        setLocationRelativeTo(parent);
        setVisible(true);
        return getResult();
    }
}

This also allows for modal dialogs in modal dialogs.

Thanks for all your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T10:37:21+00:00Added an answer on June 6, 2026 at 10:37 am

    Not sure what exactly you have as a problem, but here is an example on how you can have multiple modal dialogs:

    import java.awt.BorderLayout;
    import java.awt.Window;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    
    public class TestDialog {
    
        protected static void initUI() {
            JPanel pane = newPane("Label in frame");
            JFrame frame = new JFrame("Title");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(pane);
            frame.pack();
            frame.setVisible(true);
    
        }
    
        public static JPanel newPane(String labelText) {
            JPanel pane = new JPanel(new BorderLayout());
            pane.add(newLabel(labelText));
            pane.add(newButton("Open dialog"), BorderLayout.SOUTH);
            return pane;
        }
    
        private static JButton newButton(String label) {
            final JButton button = new JButton(label);
            button.addActionListener(new ActionListener() {
    
                @Override
                public void actionPerformed(ActionEvent e) {
                    Window parentWindow = SwingUtilities.windowForComponent(button);
                    JDialog dialog = new JDialog(parentWindow);
                    dialog.setLocationRelativeTo(button);
                    dialog.setModal(true);
                    dialog.add(newPane("Label in dialog"));
                    dialog.pack();
                    dialog.setVisible(true);
                }
            });
            return button;
        }
    
        private static JLabel newLabel(String label) {
            JLabel l = new JLabel(label);
            l.setFont(l.getFont().deriveFont(24.0f));
            return l;
        }
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    initUI();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using nyroModal I have setup a modal window with some text boxes. This window
I have a main Window.Then if you touch settings button a new modal Window
I am using jQuery UI dialog for modal popups. I have some iframes in
I have modal dialog popups filled with various videos, played by JW Player. I
I have a problem with Jquery UI modal dialogs. I have modal dialog (dialogA),
I have a modal dialog that is created with the following: procedure TFormCompose.createParams(var Params:
I have a modal dialog plugin written in jquery, that binds to the click
I have a modal dialog box presented in Yahoo UI. The user selects a
I have a modal popup extender which is triggered by gridview onRowCommand. The gridview
I have a modal which displays a UIImagePicker and allows the user to take

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.