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

  • Home
  • SEARCH
  • 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 9225449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:34:45+00:00 2026-06-18T04:34:45+00:00

I’m trying to have Java Swing dialog be created but I don’t want to

  • 0

I’m trying to have Java Swing dialog be created but I don’t want to have the dialog to take focus away from whatever is currently focused. So for example, if you’re editing a word doc and a different application creates a dialog, you should see the dialog but the word doc should remain in focus so that you can keep editing.

I’ve tested the following code on Mac OSX and on Ubuntu 12.04. On Mac, the code creates dialogs that do not take the focus like I want. On Ubuntu, the dialogs take the focus, and I can’t type while they are being created.

I really hope this isn’t operating system specific. Is there any way to achieve what I’m trying to do on all platforms (or at least Ubuntu)?

import javax.swing.*;
import java.awt.Color;
import java.util.Random;

public class Focus {
    private static Random r = new Random();

    public static void main(String[] args) {
        while(true) {   
            try {
                Thread.sleep(500);
                createObject(r.nextInt(1000), r.nextInt(600));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void createObject(int x, int y) {
        JDialog testDialog = new JDialog();
        testDialog.setSize(50, 50);
        testDialog.setLocation(x, y);
        testDialog.setAlwaysOnTop(true);
        testDialog.setUndecorated(true);
        testDialog.setFocusable(false);
        testDialog.setEnabled(false);
        testDialog.setVisible(true);
    }
}
  • 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-18T04:34:46+00:00Added an answer on June 18, 2026 at 4:34 am

    Maybe:

    testDialog.setFocusableWindowState(false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I have a French site that I want to parse, but am running into
I want to count how many characters a certain string has in PHP, but
This could be a duplicate question, but I have no idea what search terms
I have a text area in my form which accepts all possible characters from
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have been unable to fix a problem with Java Unicode and encoding. The
I want to construct a data frame in an Rcpp function, but when I

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.