Java: Keep window fullscreen in second monitor when not focused
Asked Answered
W

2

3

I am writing a java application that takes advantage of a dual monitor set up. I have two windows:

  • Window 1 - Main GUI
  • Window 2 - Full Screen on Second monitor

My Problem: The second window only stays full screen when it has the focus. If I click back on window 1 or change the focus to something else, window 2 minimizes. Is there someway to make window 2 stay full screen when it doesn't have focus?

Here is my code for making the second window full screen on the second monitor:

        frame.setExtendedState(Frame.MAXIMIZED_BOTH);
        frame.setUndecorated(true);
        frame.setVisible(true);
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] gd = ge.getScreenDevices();
        gd[1].setFullScreenWindow(frame); //gets the 2nd display.
Weathercock answered 11/7, 2014 at 18:29 Comment(0)
L
3

Try getting the size of the second monitor then instead of setting the fullscreen monitor set the size of the the second frame. Also try setting the second frame to always on top.

Lanciform answered 11/7, 2014 at 18:35 Comment(4)
I'll try the size thing. What do you mean by "getting the site"? and how would I set the second frame to "always on top"? Thanks!Weathercock
The site is a type. Meant to say size. Jframe has a function called always on top where no other frame can go on top. I believe it isframe.setAlwaysOnTop(true);Lanciform
And also you have to set the location to the width of the first screen plus one pixel and the y to 0.Lanciform
You're on to something! I tried it as you said, and it almost worked! My monitors are of different sizes so it didn't look quite right, but It still stayed active! I suppose some additional tinkering is required.Weathercock
D
1

It works with the comment from TameHog. Your code becomes:

    frame.setExtendedState(Frame.MAXIMIZED_BOTH);
    frame.setUndecorated(true);
    frame.setVisible(true);
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gd = ge.getScreenDevices();

    // gd[1].setFullScreenWindow(frame); //gets the 2nd display.
    frame.setAlwaysOnTop(true);
    frame.setSize(gd[1].getDefaultConfiguration().getBounds().getSize());
    frame.setLocation(gd[1].getDefaultConfiguration().getBounds().getLocation());
Darla answered 19/5, 2021 at 16:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.