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 8981583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:22:23+00:00 2026-06-15T20:22:23+00:00

I have developed Swing application in which I have used JDialog to show popup.

  • 0

I have developed Swing application in which I have used JDialog to show popup.

But the problem is when I press alt+tab it shows only the dialog not the application. I also tried the modal for dialog.

My requirement is when the dialog opened on application and I press the alt+tab key it switch to another X application and again when I press alt+tab key it display dialog opened on my application. Currently it shows dialog opened but alone not with application.

How I can meet this requirement using JDialog?

Here is sample code

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
*$Id$
*/
public class Main
{
    public static void main(final String[] args)
    {
        final JFrame jFrame = new JFrame();
        jFrame.setSize(300, 200);
        final JPanel panel = new JPanel();
        final JButton button = new JButton("click here to open dialog");
        final ProductDialog dialog = new ProductDialog();
        button.addActionListener(new ActionListener()
        {

            @Override
            public void actionPerformed(final ActionEvent e)
            {
                dialog.setVisible(true);
            }
        });
        panel.add(button);
        jFrame.add(panel);
        jFrame.setVisible(true);
    }
}

And The dialog is as under

import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class ProductDialog extends JDialog
{
    private static final long serialVersionUID = 1L;

    public ProductDialog()
    {
        this.add(new JPanel().add(new JLabel("Test")));
        this.setSize(150, 100);
        this.setModal(true);
        this.setLocationRelativeTo(null);
    }
}

Here is an image of the visual effect of a small app. that is currently displaying a security dialog in alt+tab on Windows 7. The app. itself is already visible on-screen, though the security dialog (upper left) is all that is shown in the smaller icons.

enter image description here

  • 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-15T20:22:24+00:00Added an answer on June 15, 2026 at 8:22 pm

    You need to set the parent window of the dialog to the Frame of your application.

    Small example:

    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.SwingUtilities;
    
    public class TestDialog {
    
        protected void initUI() {
            JFrame frame = new JFrame(TestDialog.class.getSimpleName());
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            final JButton button = new JButton("Click me to open dialog");
            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(new JLabel("A dialog"));
                    dialog.pack();
                    dialog.setVisible(true);
                }
            });
            frame.add(button);
            frame.pack();
            frame.setVisible(true);
        }
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    new TestDialog().initUI();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a Java Swing application, which uses the SwingWorker class to perform
I have developed a little Swing application in which i have added a Square
I have developed a little swing application in which i have drawn a square.Now
I have developed a small swing application in which there is a square rotating
I have developed a java swing client-server application. The server has many services like
We have a desktop client application developed in Swing. This application interacts with backend
I have a Java Swing application, developed on Mac OS X 10.5 using Java
I have developed a desktop database application. But the interface is not rich. So
I have developed a Java Swing application, and it will be installed on multiple
I have developed a swing application that displays images, so I have a large

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.