Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Swing application window disappears when moved to another screen/desktop/display on Mac OS X

Tags:

java

macos

swing

My Java Swing application window disappears whenever I drag it with the mouse from one monitor to another. It is visible while I drag it, but it disappears immediately when I release the mouse button. I would rather that the window didn't disappear. Why does it disappear?

When I activate Mission Control, the Swing Window appears at the bottom of the desktop where I dragged it. Deactivating Mission Control causes it to slide off the bottom of the screen.

It doesn't matter which Java Swing application I run. For those who want the code, here's a simple Java Swing application that exhibits the behavior I'm describing, enjoy:

import java.awt.*;
import javax.swing.*;

class SimpleSwing {
    public static void main(final String... args) {
        SwingUtilities.invokeLater(new Runnable() {
                @Override public void run() {
                    JFrame frame = new JFrame();
                    JPanel contentPane = new JPanel();
                    contentPane.add(new JLabel("Hello World!"));
                    frame.setContentPane(contentPane);
                    frame.pack();
                    frame.setVisible(true);
                }
            });
    }
}

My environment is Oracle Java JDK (latest as of this writing) on Mac OS X Yosemite (latest as of this writing):

java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

OS X Yosemite Version 10.10.2 (14C1510)
Darwin Kernel Version 14.1.0
like image 667
Greg Mattes Avatar asked Mar 20 '15 01:03

Greg Mattes


People also ask

How to stop OS/X from putting an application off screen?

I want to know how to stop OS/X from putting an application off screen in the first place. Very annoying when you are working and concentrating and the screen just disappears from view. Robsays July 10, 2019 at 7:37 am Hold down ctrl and alt, grab bottom corner of after effects window and drag. Top of window should drop down.

Why can’t I See my off-screen window in macOS?

macOS: Bring Off-Screen Window Back Onto Screen By Mitch Bartlett29 Comments You have the application open, but you can’t see the window for it in macOS? Try these tips. Fix 1 – Zoom Select the application in the dock, then choose “Window” > “Zoom“. Fix 2 – Resolution Select the Apple Menu, then choose “System Preferences…” > “Displays“.

How do I force a window back to the screen?

Select the application in the dock, then choose “Window” > “Zoom“. Fix 2 – Resolution Select the Apple Menu, then choose “System Preferences…” > “Displays“. Ensure “Scaled” is selected under “Resolution“. Choose any other setting. This should force the window for the application back on the screen where you can drag it to a safe place.

How do I force quit an application on my Mac?

Try selecting “Apple” Menu, then “Force Quit… From there, select the application, then “Force Quit“. This should allow you to start the application new, and hopefully where it’s back on the screen. Hopefully, one of the above fixes worked for you.


2 Answers

Step: Before frame.setVisible(true); you can add below two line of code and then test again.

frame.setLocation(500, 500); frame.setAlwaysOnTop(true);

like image 107
Sadhan Sarker Avatar answered Sep 21 '22 18:09

Sadhan Sarker


Try the following:

  1. Go to System Preferences > Displays > Arrangement
  2. Align the two rectangles perfectly
  3. See if it works
  4. If not, change the order of the 2 rectangles (and the monitors or plug them in differently)

Hope this helps, but I'm not sure if it is the solution.

like image 23
maraca Avatar answered Sep 21 '22 18:09

maraca