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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:19:16+00:00 2026-05-25T00:19:16+00:00

In another thread I stated that I liked to center my GUIs by doing

  • 0

In another thread I stated that I liked to center my GUIs by doing something like this:

JFrame frame = new JFrame("Foo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new HexagonGrid());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);

But Andrew Thompson had a different opinion, to instead call

frame.pack();
frame.setLocationByPlatform(true);

and inquiring minds want to know why?

  • 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-25T00:19:17+00:00Added an answer on May 25, 2026 at 12:19 am

    To my eye, a GUI in the middle of the screen looks so.. “splash-screen’ish”. I keep waiting for them to disappear and the real GUI to appear!

    Since Java 1.5 we’ve had access to Window.setLocationByPlatform(boolean). which..

    Sets whether this Window should appear at the default location for the native windowing system or at the current location (returned by getLocation) the next time the Window is made visible. This behavior resembles a native window shown without programmatically setting its location. Most windowing systems cascade windows if their locations are not explicitly set. The actual location is determined once the window is shown on the screen.

    Have a look at the effect of this example that puts 3 GUIs into the default positions as chosen by the OS – on Windows 7, Linux with Gnome & Mac OS X.

    Stacked windows on Windows 7 enter image description here
    Stacked windows on Mac OS X

    (3 lots of) 3 GUIs neatly stacked. This represents ‘the path of least surprise’ for the end user, since it is how the OS might position 3 instances of the default plain-text editor (or anything else, for that matter). My thanks to trashgod for the Linux & Mac. images.

    Here is the simple code used:

    import javax.swing.*;
    
    class WhereToPutTheGui {
    
        public static void initGui() {
            for (int ii=1; ii<4; ii++) {
                JFrame f = new JFrame("Frame " + ii);
                f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                String s =
                    "os.name: " + System.getProperty("os.name") +
                    "\nos.version: " + System.getProperty("os.version");
                f.add(new JTextArea(s,3,28));  // suggest a size
                f.pack();
                // Let the OS handle the positioning!
                f.setLocationByPlatform(true);
                f.setVisible(true);
            }
        }
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater( new Runnable() {
                public void run() {
                    try {
                        UIManager.setLookAndFeel(
                            UIManager.getSystemLookAndFeelClassName());
                    } catch (Exception useDefault) {}
                    initGui();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I originally started this question in another thread, but that thread was sorta, kinda
Anytime the beginner asks something like: How to update the GUI from another thread
[Note: There is another thread about this problem but it did not answer the
I am tring to setText in another thread, that is, child thread. But for
I have a windows form on the main thread and another thread that does
I recently started this question in another thread (to which Reed Copsey graciously responded)
Answering another thread (see stackoverflow: generate css color schemes ) I bumped into the
I want to access a scrollviewer from another thread. Please tell me how to
As I don't want to hijack another thread here comes my question about mappings.
I want to update a Object in another thread, and then access it in

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.