Custom monitor resolution not recognized by Java

My weird initial monitor resolution is not recognized by Windows, so I have to set a custom resolution for it. The problem is that java does not recognize it, because it is not included in the list of "approved" Win7, so full-screen mode is "stuck". Netbeans comes out of full screen mode, so there should be a way around this. Does anyone know this?

// Edit (3/29/2010): It seems that NetBeans is faking full-screen mode, and not actually switching to full-screen exclusive mode, so in reality this cannot be resolved. At the moment, I'm pretending too. It seems that java should recognize the active DisplayMode as valid.

This example reproduces the problem:


package resolutionexample;

import java.awt.Dimension;
import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class Main {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable(){
            public void run() {
                GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
                GraphicsDevice gd = ge.getDefaultScreenDevice();

                DisplayMode currentDM = gd.getDisplayMode();

                boolean currentInAvailable = false;

                System.out.println("Available resolutions:");
                for ( DisplayMode availDM : gd.getDisplayModes() ){
                    //System.out.println(availDM.getWidth() + "x" + availDM.getHeight());
                    if ( availDM.equals(currentDM) ){
                        currentInAvailable = true;
                    }
                }

                System.out.println("Current resolution: " + currentDM.getWidth() + "x" + currentDM.getHeight() );

                System.out.println("Current in available: " + currentInAvailable);


                JFrame frame = new JFrame("Resolution Bug Example");
                frame.setVisible(true);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                if ( !gd.isFullScreenSupported() ){System.exit(0);}

                gd.setFullScreenWindow(frame);

                gd.setFullScreenWindow(null);
            }
        });
    }
}

1680x1050 ( ):


run:
Available resolutions:
Current resolution: 1680x1050
Current in available: false
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Invalid display mode
        at sun.awt.Win32GraphicsDevice.setDisplayMode(Win32GraphicsDevice.java:393)
        at sun.awt.Win32GraphicsDevice.setFullScreenWindow(Win32GraphicsDevice.java:329)
        at resolutionexample.Main$1.run(Main.java:43)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
BUILD SUCCESSFUL (total time: 2 seconds)

, 1024x768 :


run:
Available resolutions:
Current resolution: 1024x768
Current in available: true
BUILD SUCCESSFUL (total time: 2 seconds)
+5
2

? ?

Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().
                 getMaximumWindowBounds();
JFrame frame = new JFrame();
frame.setPreferredSize(new Dimension(rect.width, rect.height));

MainWindow netbeans: -)

+2

Windows 7?

PowerStrip (http://entechtaiwan.com/util/ps.shtm.), XP.

+1

All Articles