Swing MacBook Invalid Display mode

441 views Asked by At

Display mode settings : fullscreen.displaywidth =(1440,900,16,0)

Current display resolution: 1440*900 scaled.

Code :

fullscreen.pixelperframe = ((fullscreen.speed - 10) > 1) ? (fullscreen.speed-10) : 1;   
DisplayMode dmode = new DisplayMode(fullscreen.displaywidth,fullscreen.displayheight,16,0);    

Exception in thread "main" java.lang.IllegalArgumentException: Invalid display mode at sun.awt.CGraphicsDevice.nativeSetDisplayMode(Native Method) at sun.awt.CGraphicsDevice.setDisplayMode(CGraphicsDevice.java:234) at FullScreen.main(FullScreen.java:237)

System Macbook Air 2012

MyQuestion :

What is the proper display mode settings that work in Macbook Air , or the code should be different.

2

There are 2 answers

1
MadProgrammer On BEST ANSWER

You can use GraphicsDevice#getDisplayModes to list the available DisplayModes that a device can support, for example

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
for (DisplayMode dm : gd.getDisplayModes()) {
    System.out.println(dm.getWidth() + "x" + dm.getHeight() + "@" + dm.getRefreshRate());
}

Which on mini-mac outputs...

2560x1600@32
1280x1024@75
1024x768@75
1024x768@60
800x600@75
800x600@60
640x480@75
640x480@60
1280x1024@60
1600x1200@60
640x480@85
800x600@85
848x480@60
1024x768@85
1280x960@60
1280x960@75
1280x960@85
1280x1024@85
1360x768@60
1920x1080@60
1280x800@32
800x500@32
1024x640@32
1344x1008@32
1344x840@32
1600x1000@32
2048x1280@32
0
user2936008 On

I was able to run the swing using :

DisplayMode dmode = new DisplayMode(800, 600, 32, DisplayMode.REFRESH_RATE_UNKNOWN);