Is it possible to use java gui frameworks (such as Swing, SWT or javaFX) without desktop environment, such as Gnome?
Although I haven't encountered this situation myself, I would suspect that this would be the case where the HeadlessException
would come into play.
The Javadoc for HeadlessException
says the following:
Thrown when code that is dependent on a keyboard, display, or mouse is called in an environment that does not support a keyboard, display, or mouse.
The HeadlessException
is thrown by the constructors of various classes that deal with the GUI, such as Dialog
and JFrame
, so I would suspect that in non-GUI environments, the HeadlessException
will be thrown when attempting to use a GUI toolkit.
If you're looking to do testing, or need to use some of the image manipulation classes on a server, then a virtual framebuffer will work. I'll assume you're running Linux; I've had good luck with Xvfb.
Basically, no.
The GUI stuff expects something to actually DO the things requested by the GUI code, but the headless property allows much code to run without. Note: This is only for Unixoid JVM's - the Windows one can always sneak into the GUI which is always there.
The typical way to circumvent this is to have a VNC Xserver running or similar, since that provides the necessary functionality without requering graphics hardware for the X server to cuddle.
The crucial question now is, what do you want to achieve?
Setting -Djava.awt.headless=true
or System.setProperty("java.awt.headless","true")
allows using graphics with some limitations. Drawing into an offscreen buffer works well, as discussed here in the context of JFreeChart running on a web server.