Setting the Screen Size, Refresh Rate, or Number of Colors

Typically, the properties of the screen can only be changed while in full-screen mode (see Enabling Full-Screen Mode. See also Getting the Available Screen Sizes, Refresh Rates, and Number of Colors.
// Determine if the display mode can be changed GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gs = ge.getDefaultScreenDevice(); // Determine if the display mode can be changed boolean canChg = gs.isDisplayChangeSupported(); if (canChg) { // Change the screen size and number of colors DisplayMode displayMode = gs.getDisplayMode(); int screenWidth = 640; int screenHeight = 480; int bitDepth = 8; displayMode = new DisplayMode( screenWidth, screenHeight, bitDepth, displayMode.getRefreshRate()); try { gs.setDisplayMode(displayMode); } catch (Throwable e) { // Desired display mode is not supported; leave full-screen mode gs.setFullScreenWindow(null); } } else if (gs.getFullScreenWindow() != null) { // Try enabling full-screen mode; // see Enabling Full-Screen Mode } else { // Display mode cannot be changed }

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.