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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:45:33+00:00 2026-05-30T08:45:33+00:00

We have an application which, as its first UI action, displays a modal JDialog

  • 0

We have an application which, as its first UI action, displays a modal JDialog without a parent frame.

public LoginDialog(Frame owner, Config config, Object... params) {
    super((Frame)null, true);

It unfortunately has the annoying characteristic that when it appears, although it comes to the front, it does not grab the focus.

So the user, after launching the application by double-clicking on the start menu, has to use the mouse to select the “login” dialog and type in information.

Is there a way to make this JDialog grab the focus when it appears in the front?

I’ve tried calls to “requestFocus” before, after and via invokeLater “during” the call to setVisible(true) – but none of these seems to have any effect.

How do we make a modal dialog grab the focus?

UPDATE: The issue was the code used to try to present a background “wait window”. This window was displayed “behind” the login dialog as a hack so that when the dialog disappeared the user would see the “Please wait” message. As it was the first window created by the application, it got the focus. I am not sure if there would have been a way to make the dialog gain the focus again inside the event dispatch thread with this hack – but I fixed it by un-hacking it and doing things properly.

  • 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-05-30T08:45:34+00:00Added an answer on May 30, 2026 at 8:45 am

    First, it a little strange that modal dialog is parent-less. The point in modal dialog is that it is displayed on its parent and does not allow to access parent.

    So, the first recommendation is to make it non-modal. I believe it will work.

    BTW I have just tried to create such dialog and have not problems with focus. Try probably to simplify your code:

        JDialog d = new JDialog();
        d.setSize(200, 200);
        d.setVisible(true);
    

    This works for me and I believe will work for you. Now start changing this simple code towords your real application code. At some point it will stop working and you will see where the problem is.

    If nothing helps try to use the trick I described in this article. Look for title “Portable window activation”. I hope it will help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application which tries to load some expected registry settings within its
I have an existing application which does all of its logging against log4j. We
I have 3 timers running on my application which takes care of different action.
I have application which needs to use a dll (also written by me) which
I have an application which really should be installed, but does work fine when
I have an application which extracts data from an XML file using XPath. If
We have an application which needs to use Direct3D. Specifically, it needs at least
I have an application which behaves as a slideshow for all pictures in a
I have an application which is a portal application and I want to allow
I have an application which takes a string value of the form %programfiles%\directory\tool.exe from

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.