< prev index next >
src/java.desktop/share/classes/java/awt/Desktop.java
Print this page
@@ -277,10 +277,12 @@
sm.checkPermission(new RuntimePermission(
"canProcessApplicationEvents"));
}
}
+ private static Desktop desktop;
+
/**
* Returns the {@code Desktop} instance of the current
* desktop context. On some platforms the Desktop API may not be
* supported; use the {@link #isDesktopSupported} method to
* determine if the current desktop is supported.
@@ -298,15 +300,22 @@
throw new UnsupportedOperationException("Desktop API is not " +
"supported on the current platform");
}
sun.awt.AppContext context = sun.awt.AppContext.getAppContext();
- Desktop desktop = (Desktop)context.get(Desktop.class);
+
+ Desktop desktop = (context == null)
+ ? Desktop.desktop
+ : (Desktop)context.get(Desktop.class);
if (desktop == null) {
desktop = new Desktop();
+ if (context != null) {
context.put(Desktop.class, desktop);
+ } else {
+ Desktop.desktop = desktop;
+ }
}
return desktop;
}
< prev index next >