加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-15 04:20:57 所属栏目:Java 来源:网络整理
导读:我在我的Raspberry Pi上安装了JDK 8,并尝试运行 javaFx示例应用程序.我的操作系统是Raspbian.我正在使用Netbeans 8附带的“DigitalClock”示例应用程序.该应用程序在Pi上启动并运行,但是当它执行时几乎全屏并且在主视图周围有这么大的黑色边框.此外,应用程序
我在我的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 07001.

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();
        }
    }
);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读