Michelle D
Michelle D

Reputation: 99

Java Window Size Limitations on OSX Yosemite (10.10.5)

I am attempting to resize a window from a Java application to span 8 connected monitors. All monitors are the exact same Dell monitor with 2560 X 1600 resolution each. The monitors are laid out so that there are 4 across and 2 down. This means that the total resolution across all 8 monitors is 10240 X 3200. However, no Java application seems capable of expanding past about 4096 X 3200. Since I know Java applications were able to scale across all 8 monitors before I updated the system to OSX, it makes me wonder if Java doesn't play nicely with OSX.

Has anyone experienced similar issues? Anyone know how to fix it or if I can?

Previous Findings

System Details OS: OSX Yosemite (10.10.5), Processor: 2X2.26 GHz Quad-Core Intel Xeon, Memory: 16 BG, Graphics: NVIDIA GeForce GT 120 512 MB

Sample Java Program

import javax.swing.*;

class WindowTest extends JFrame {
  public WindowTest() {
    setSize(10240, 3200);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
  }

  public static void main (String[] args) {
    WindowTest w = new WindowTest();
    w.setVisible(true);
  }
}

Upvotes: 4

Views: 447

Answers (1)

sorifiend
sorifiend

Reputation: 6307

Very interesting question, and nice SSCCE but I am unable to test the following code since my machine only has one display port, but I hope this may be of some help.

The call to setSize(10240, 3200) is often ignored, the javadoc tells us

The method changes the geometry-related data. Therefore, the native windowing system may ignore such requests, or it may modify the requested data, so that the Window object is placed and sized in a way that corresponds closely to the desktop settings.

Instead I suggest using both of the following to try and force a size, and call pack() later:

setMinimumSize(new Dimension(10240, 3200));
setPreferredSize(new Dimension(10240, 3200));

In addition to this you can and should specify the JFrame location relative to the left/top most screen, something a little like this: (Edit: Updated to reflect the comments and added pack() where needed)

import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

class WindowTest extends JFrame
{
    public WindowTest()
    {
        setLocation(0, 0);

        //Set your window to a specific size, we can force this by calling pack() later
        setMinimumSize(new java.awt.Dimension(10240, 3200));
        setPreferredSize(new java.awt.Dimension(10240, 3200));
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
    public static void main (String[] args)
    {
        try
        {
            // Set cross-platform Java L&F (also called "Metal")
        UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        }
        catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException e)
        {
            //Do nothing, the progam will default to automatic system assigned L&F
            System.out.println("Failed to set L&F to \"Metal\": "+e.getMessage());
        }
        WindowTest w = new WindowTest();
        w.setVisible(true);
        //Then try pack() to force your window size, and hopefully ignore OS sizing
        w.pack();
    }
}

This should achieve the frame size you want.

Upvotes: 1

Related Questions