jdk/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java
Print this page
@@ -23,10 +23,11 @@
* questions.
*/
package sun.awt;
+import java.awt.AWTError;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.awt.peer.ComponentPeer;
@@ -91,11 +92,13 @@
protected native int getNumScreens();
protected native int getDefaultScreen();
public GraphicsDevice getDefaultScreenDevice() {
- return getScreenDevices()[getDefaultScreen()];
+ GraphicsDevice[] screens = getScreenDevices();
+ int index = getDefaultScreen();
+ return screens[0 < index && index < screens.length ? index : 0];
}
/**
* Returns the number of pixels per logical inch along the screen width.
* In a system with multiple display monitors, this value is the same for
@@ -125,10 +128,13 @@
*/
@Override
public void displayChanged() {
// getNumScreens() will return the correct current number of screens
GraphicsDevice newDevices[] = new GraphicsDevice[getNumScreens()];
+ if (newDevices.length == 0) {
+ throw new AWTError("no screen devices");
+ }
GraphicsDevice oldScreens[] = screens;
// go through the list of current devices and determine if they
// could be reused, or will have to be replaced
if (oldScreens != null) {
for (int i = 0; i < oldScreens.length; i++) {