Why does my JavaFx application not have a frame when run on my RaspberryPi?


I installed JDK 8 on my Raspberry Pi and am trying to run a javaFx sample application. My OS is Raspbian. I am using the "DigitalClock" sample application that comes with Netbeans 8. The application launches and runs on the Pi, but when it does it is almost full screen and has this large black border around the main view. Also, there is no frame on the app. No exit or minimize buttons. Frankly, I don't know how to shutdown the app or just run it in a smaller window. To resume using my Pi, I have to unplug it and reboot.

What am I doing wrong here?

7/2/2014 6:15:12 PM

Accepted Answer

A JavaFX developer, Daniel Blaukopf, explained this in a Raspberry Pi forum:

JavaFX on the Raspberry Pi uses the framebuffer, not the X11 desktop. It takes over the whole screen. See a open-jfx wiki page on the Raspberry Pi.

JavaFX with accelerated graphics on the Raspberry Pi is only in full-screen mode. It would be possible to do non-accelerated graphics in a window, but the performance of that would be quite bad. The EGL implementation on the Pi doesn't support OpenGL in an X11 window, at least not least time I checked.

I'm also going to copy the linked information from the open-jfx wiki here in case the wiki page dies:

JavaFX on the Raspberry Pi takes over the whole screen and captures all Linux input devices. While this will generally be the behavior you want in a deployed application, it is less convenient for development because you can't stop an application using control-C unless the JavaFX application has a KeyEvent handler that listens for control-C and calls Platform.exit(). There's nothing unusual about this - many Linux full-screen console applications have the same behavior - but it is often useful to have a quick way to end an application during development without changing the application code.

There are two ways to run applications with the ability to be terminated by control-C:

  1. Run applications over an SSH connection from a PC. This gives most control over the device, because once you have SSH connections set up then you can use them for other purposes as well.

  2. Alternatively, you can use a built-in debugging feature to trap control-C. If you set the environment variable JAVAFX_DEBUG=1 before starting Java then JavaFX will exit when you press control-C. For example:

/opt/jdk1.8.0/bin/java -cp Stopwatch.jar stopwatch.MainScreen

The JAVAFX_DEBUG environment variable is only for use in development and you shouldn't rely on it for deployment of your application. In the future this functionality might be specified differently or be removed.

Answers to additonal questions

Is there a "best practice" for allowing a user to exit a JavaFX application that is running in full screen mode? I would want my users to be able to start my app, use it, and then close it.

You should code your application to include a reasonably obvious UI element that will allow the user to close the application. For example, by placing a close button on your main application screen or providing a close menu option:

Button close = new Button("Close");
    new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            // or Platform.exit();

If you also want the application to respond and exit on a key combination, such as Ctrl+C, then you could additionally include a key combination accelerator:

    new Runnable() {
        public void run() {
7/2/2014 7:26:49 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow