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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:53:29+00:00 2026-05-29T10:53:29+00:00

How can I reference a top-level container (e.g. a JFrame ) throughout an application

  • 0

How can I reference a top-level container (e.g. a JFrame) throughout an application without making it a singleton? The reason I ask is that I’m trying to avoid the singleton antipattern.

Anyway, I find that when I need another top-level container (e.g. a JDialog) to display a simple message to the user, I want this dialog to be placed directly over the aforementioned JFrame using setLocationRelativeTo(frame). But the only way I can do so (at the moment), is to make a single instance of the JFrame and access it using a static getInstance method.

So, is there a way to reference a top-level container without having to resort to the singleton pattern? Please let me know if anyone needs more information!

Thanks.

  • 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-29T10:53:30+00:00Added an answer on May 29, 2026 at 10:53 am

    If you have a reference to any Swing component held in the top level window, such as can be obtained from an Event object’s (such as an ActionEvent) getSource() method, you can use this to get the top level window via a SwingUtilities method:

    SwingUtilities.getWindowAncestor(anyComponent);
    

    This class also has other useful and similar methods such as windowForComponent(Component c) getDeepestComponentAt(...) and getRoot(Component c)

    Otherwise you can always pass references via constructor or setter parameters.

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

Sidebar

Related Questions

How do I create a resource that I can reference and use in various
It seems that Visual Basic can not reference sheets according to user-modified sheet names.
I have a class that extends Composite and contains a DisclosurePanel at the top-level
I have a silverlight class library (not a top-level application) with several user controls
I am trying to maximize JFrame from within JMenuBar, I can not pass a
pg474, K.N.King The general rule in C99 is that if all top-level declarations of
I am trying to configure a JNDI data source that can be used from
i can reference link with specific id with following code $(document).ready(function(){ $(a#example_link_id).click(function(event){ var url
In JSP I can reference a bean's property by using the tag ${object.property} Is
In Ruby you can reference variables inside strings and they are interpolated at runtime.

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.