3

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?

MeBigFatGuy
  • 28,272
  • 7
  • 61
  • 66
  • 2
    Maybe this is another way to achieve your goal. What are you actually trying to accomplish? – jzd Apr 08 '11 at 18:47
  • just playing around. was looking at testing swing code, and saw how most tools that do it, do it, and didn't particularly like it. I didn't have anything real concrete in mind, just exploring. – MeBigFatGuy Apr 08 '11 at 21:47

1 Answers1

3

A Java top-level container such as JFrame requires access to a peer component native to the host platform, typically via JNI. Alternatively, you may be able to use a BufferedImage or java.awt.headless mode, as discussed here.

Addendum:

I wonder if "any human" can replace how peers are selected.

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.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Sorry this is a bit sketchy, but it might offer a foundation for clarification. – trashgod Apr 08 '11 at 19:53
  • i suppose you can't print JFrames either then, i wonder if 'any human' can replace how peers are selected. Odd that the peer selection algorithm isn't tied to the GraphicsConfiguration. – MeBigFatGuy Apr 08 '11 at 21:48