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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:03:53+00:00 2026-06-17T09:03:53+00:00

I am writing a program designed to work on a two monitor system. I

  • 0

I am writing a program designed to work on a two monitor system. I have to separate JFrame objects, and have it so be default, the first frame instance opens. The user then has to drag that frame over to a specific monitor, or leave it in place. When they click a button on that frame, I want the program to open up the second frame on the opposite monitor.

So, How would I figure out which monitor a frame object is on, and then tell another frame object to open on the opposite one?

  • 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-17T09:03:54+00:00Added an answer on June 17, 2026 at 9:03 am

    Looking up GraphicsEnvironment, you can easily find out the bounds and location of each screen. After that, it is just a matter of playing with the location of the frames.

    See small demo example code here:

    import java.awt.Frame;
    import java.awt.GraphicsDevice;
    import java.awt.GraphicsEnvironment;
    import java.awt.Point;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;
    
    public class TestMultipleScreens {
    
        private int count = 1;
    
        protected void initUI() {
            Point p = null;
            for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
                p = gd.getDefaultConfiguration().getBounds().getLocation();
                break;
            }
            createFrameAtLocation(p);
        }
    
        private void createFrameAtLocation(Point p) {
            final JFrame frame = new JFrame();
            frame.setTitle("Frame-" + count++);
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            final JButton button = new JButton("Click me to open new frame on another screen (if you have two screens!)");
            button.addActionListener(new ActionListener() {
    
                @Override
                public void actionPerformed(ActionEvent e) {
                    GraphicsDevice device = button.getGraphicsConfiguration().getDevice();
                    Point p = null;
                    for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
                        if (!device.equals(gd)) {
                            p = gd.getDefaultConfiguration().getBounds().getLocation();
                            break;
                        }
                    }
                    createFrameAtLocation(p);
                }
            });
            frame.add(button);
            frame.setLocation(p);
            frame.pack(); // Sets the size of the unmaximized window
            frame.setExtendedState(Frame.MAXIMIZED_BOTH); // switch to maximized window
            frame.setVisible(true);
        }
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    new TestMultipleScreens().initUI();
                }
            });
        }
    
    }
    

    Yet, consider reading carefully The Use of Multiple JFrames, Good/Bad Practice? because they bring very interesting considerations.

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

Sidebar

Related Questions

I am in the preparation stages of writing my first real program. I've designed
Im writing a program that should read input via stdin, so I have the
I was writing a program to concatenate two arrays in C. I am allocating
I've been writing a program in C to move the first 4 bits of
I'm writing a program that's parsing an XML file to java objects using smooks.
I am writing a program that is designed to play videos (not sure if
I have a program (that I did not write) which is not designed to
I've been writing a simple program, and I've designed a simple text abstraction -
I have tried writing program that plays a sound file but have been unsuccessful
Good day! I have met problem with synchronizing threads. I am writing program which

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.