gpt4 book ai didi

javafx - 为什么我的 JavaFx 应用程序在 RaspberryPi 上运行时没有框架?

转载 作者:行者123 更新时间:2023-12-02 08:53:48 25 4
gpt4 key购买 nike

我在 Raspberry Pi 上安装了 JDK 8,并尝试运行 javaFx 示例应用程序。我的操作系统是 Raspbian。我正在使用 Netbeans 8 附带的“DigitalClock”示例应用程序。该应用程序在 Pi 上启动并运行,但当它启动时,它几乎是全屏的,并且主视图周围有一个大的黑色边框。此外,应用程序上没有框架。没有退出或最小化按钮。坦率地说,我不知道如何关闭该应用程序或只是在较小的窗口中运行它。要恢复使用我的 Pi,我必须拔掉它并重新启动。

我在这里做错了什么?

最佳答案

JavaFX 开发人员 Daniel Blaukopf 在 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.

我还将从此处复制 open-jfx wiki 的链接信息,以防 wiki 页面失效:

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:

JAVAFX_DEBUG=1
/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.

其他问题的答案

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 元素,该元素将允许用户关闭应用程序。例如,通过在主应用程序屏幕上放置关闭按钮或提供关闭菜单选项:

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

如果您还希望应用程序响应组合键(例如 Ctrl+C)并退出,那么您还可以添加组合键加速器:

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

关于javafx - 为什么我的 JavaFx 应用程序在 RaspberryPi 上运行时没有框架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24538236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com