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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:37:00+00:00 2026-05-11T19:37:00+00:00

I want to store a JFrame’s location (bounds, extendedState) when the user closes it.

  • 0

I want to store a JFrame’s location (bounds, extendedState) when the user closes it. However, when the user moves the frame onto the 2nd screen and maximizes it, how can I store that information? My naive (and single display) implementation is like this:


void saveFrame(JFrame frame) throws IOException {
    Properties props = new Properties();
    props.setProperty("State", String.valueOf(frame.getExtendedState()));
    props.setProperty("X", String.valueOf(frame.getX()));
    props.setProperty("Y", String.valueOf(frame.getY()));
    props.setProperty("W", String.valueOf(frame.getWidth()));
    props.setProperty("H", String.valueOf(frame.getHeight()));
    props.storeToXML(new FileOutputStream("config.xml"), null);
}
void loadFrame(JFrame frame) throws IOException {
    Properties props = new Properties();
    props.loadFromXML(new FileInputStream("config.xml"));
    int extendedState = Integer.parseInt(props.getProperty("State", String.valueOf(frame.getExtendedState())));
    if (extendedState != JFrame.MAXIMIZED_BOTH) {
        frame.setBounds(
            Integer.parseInt(props.getProperty("X", String.valueOf(frame.getX()))),
            Integer.parseInt(props.getProperty("Y", String.valueOf(frame.getY()))),
            Integer.parseInt(props.getProperty("W", String.valueOf(frame.getWidth()))),
            Integer.parseInt(props.getProperty("H", String.valueOf(frame.getHeight())))
        );
    } else {
        frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    }
}

How can I discover on which screen the frame is located?
How can I move a frame to the second screen and maximize it there?

  • 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-11T19:37:00+00:00Added an answer on May 11, 2026 at 7:37 pm

    To find the ID of the used graphics device:

    frame.getGraphicsConfiguration().getDevice().getIDString()
    

    Going the other way, you can find the graphics devices with:

     GraphicsEnvironment.getLocalGraphicsEnvironment().getDevices()
    

    You can then use a configuration from the device in the JFrame constructor. I don’t believe you can set it after construction.

    Of course, you should be careful not to, say, open the frame off screen because the resolution has change.

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

Sidebar

Ask A Question

Stats

  • Questions 136k
  • Answers 137k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer GCs only occur when the heap is full. When the… May 12, 2026 at 7:16 am
  • Editorial Team
    Editorial Team added an answer Add a quote around it: echo "<input type='button' value='send mails'… May 12, 2026 at 7:16 am
  • Editorial Team
    Editorial Team added an answer This will work in C# 4, where delegates have generic… May 12, 2026 at 7:16 am

Related Questions

I want to store a JFrame's location (bounds, extendedState) when the user closes it.
I want to store a large number of sound files in a database, but
I want to store a a c# DateTimeOffset value in a SQL Server 2005
I want to store a large result set from database in memory. Every record
I want to store a very large amount of vector data on a server

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.