且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在RaspberryPi上运行时,为什么JavaFx应用程序没有框架?

更新时间:2023-01-26 11:11:25

JavaFX开发人员Daniel Blaukopf在

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

Raspberry Pi上的JavaFX使用帧缓冲区,而不使用X11桌面.它占据了整个屏幕.请参阅 open-jfx Wiki页面, Raspberry Pi .

Raspberry Pi上具有加速图形的JavaFX仅处于全屏模式.可以在窗口中做非加速图形,但是那样的性能会很差. Pi上的EGL实现在X11窗口中不支持OpenGL,至少在我检查的时间中如此.

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.

如果维基页面死亡,我还将在这里复制来自open-jfx维基的链接信息:

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

Raspberry Pi上的JavaFX可以接管整个屏幕并捕获所有Linux输入设备.虽然这通常是您在已部署的应用程序中想要的行为,但开发起来不太方便,因为您无法使用Control-C停止应用程序,除非JavaFX应用程序具有KeyEvent处理程序来监听Control-C并调用Platform.exit().这没有什么不寻常的-许多Linux全屏控制台应用程序具有相同的行为-但通常有一种快速的方法可以在开发过程中结束应用程序而不更改应用程序代码,这很有用.

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.

有两种方法可以运行可被Control-C终止的应用程序:

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

  1. 通过PC上的SSH连接运行应用程序.这样就可以对设备进行大多数控制,因为一旦建立了SSH连接,您就可以将其用于其他用途.

  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.

或者,您可以使用内置的调试功能来捕获Control-C.如果在启动Java之前设置了环境变量JAVAFX_DEBUG=1,则在按Control-C时JavaFX将退出.例如:

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:

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

JAVAFX_DEBUG环境变量仅用于开发中,您不应依赖它来部署应用程序.将来可能会对此功能进行其他指定或将其删除.

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.

其他问题的答案

是否有***做法"?允许用户退出以全屏模式运行的JavaFX应用程序?我希望我的用户能够启动,使用我的应用程序,然后将其关闭.

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.

您应该对应用程序进行编码,以包含一个相当明显的UI元素,该元素将允许用户关闭该应用程序.例如,通过在主应用程序屏幕上放置一个关闭按钮或提供关闭菜单选项:

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");
close.setOnAction(
    new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            primaryStage.close();
            // or Platform.exit();
        }
    }
);

如果您还希望应用程序响应并退出某个组合键(例如 Ctrl + C ),则可以另外包含一个组合键加速器:

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:

primaryStage.getScene().getAccelerators().put(
    KeyCombination.keyCombination("CTRL+C"),
    new Runnable() {
        @Override
        public void run() {
            Platform.exit();
        }
    }
);