Greetings,
I’m trying to get a JFrame drawing in a non screen device. The JFrame constructor has a
JFrame(GraphicsConfiguration)
to seemingly allow this:
My First attempt was to create my own GraphicsConfiguration, who’s GraphicsDevice reported GraphicsDevice.TYPE_IMAGE_BUFFER when getType() was called.
However JFrame.init specifically looks for the type and throws an exception if the type isn’t TYPE_RASTER_SCREEN:
if (graphicsConfig.getDevice().getType() !=
GraphicsDevice.TYPE_RASTER_SCREEN) {
throw new IllegalArgumentException("not a screen device");
}
Next i tried to make the GraphicsDevice i returned report GraphicsDevice.TYPE_RASTER_SCREEN. This allowed the JFrame to be initialized correctly, but when it went to display it, I got
Exception in thread "main" java.lang.ClassCastException: TestGraphicsConfiguration cannot be cast to sun.awt.X11GraphicsConfig
So i’ve run out of ideas, on how to draw a JFrame that doesn’t show up on the screen, but is never the less fully layed out and functional.
Am going down a rabbit hole here, or can this be done?
A Java top-level container such as
JFramerequires access to a peer component native to the host platform, typically via JNI. Alternatively, you may be able to use aBufferedImageorjava.awt.headlessmode, as discussed here.Addendum:
I don’t know how to replace a particular peer component, but it’s possible to evoke platform-specific native components; Java Native Access (JNA) is one such avenue. As an extreme example, this 6502 JVM runs in 128K on an 8-bit processor running at 1 MHz. The demos, including source for the lower right screenshot, were compiled using
javac.