简体   繁体   English

JavaFX-屏幕关闭时的绘图组件

[英]JavaFX - Drawing component when the screen is turned off

My application works on tablet (with Windows 7) which sometimes turns off its display in order to save battery. 我的应用程序可在平板电脑(使用Windows 7)上工作,有时会关闭其显示屏以节省电池。 After touching the screen, it turns on again. 触摸屏幕后,它会再次打开。

Application should remain operational even after turning off the screen, what is, in general, accomplished (ie sounds are played). 通常,即使关闭屏幕后,应用程序也应保持可操作状态,即完成操作(即播放声音)。 The only problem is the fact that when screen is turned off and application tries to add new component to the scene (technically - add children to the displayed GridPane ), the newly added component is not visible when I touch the screen (and it turns on). 唯一的问题是,当屏幕关闭并且应用程序尝试将新组件添加到场景中时(从技术上讲-将子级添加到显示的GridPane ),当我触摸屏幕时,新添加的组件不可见(然后打开) )。

It is just like there was a cache which stores and restores displayed content when screen is turning on/off. 就像有一个缓存可以在屏幕打开/关闭时存储和还原显示的内容。 After turning screen on - when I click windows button (keyboard) or or change focus to another application - newly added component appears. 打开屏幕后-当我单击Windows按钮(键盘)或将焦点更改到另一个应用程序时-会出现新添加的组件。

I have tried setting -Dprism.dirtyopts=false but it did not change anything. 我尝试设置-Dprism.dirtyopts=false但它没有任何改变。

My Java is 7u67. 我的Java是7u67。

Is it known bug? 它是已知的错误吗? Is there any programming workaround? 有什么编程解决方法? I have tought about using WinAPI to force redraw/refresh of the application window but it seems too big for this case. 我对使用WinAPI强制重新绘制/刷新应用程序窗口有一定的了解,但在这种情况下似乎太大了。

I have just figured out "simple" workaround: 我刚刚想出了“简单”的解决方法:

import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.Kernel32;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinUser;
import com.sun.jna.ptr.IntByReference;

/** WINAPI CONSTANTS **/
private static final int RDW_UPDATENOW = 0x0100;

/**
* Redraws all windows associated with currently running process.
*/
public static void redrawApplicationWindows() {
    final int processId = Kernel32.INSTANCE.GetCurrentProcessId();
    User32.INSTANCE.EnumWindows(
        new WinUser.WNDENUMPROC() {
          @Override
          public boolean callback(WinDef.HWND hwnd, Pointer pointer) {
            IntByReference someProcessId = new IntByReference();
            User32.INSTANCE.GetWindowThreadProcessId(hwnd, someProcessId);
            if (someProcessId.getValue() == processId) {
              User32.INSTANCE.RedrawWindow(hwnd, null, null, new User32.DWORD(RDW_UPDATENOW));
            }
            return true;
          }
        }, Pointer.NULL);
}

It requires you to have jna and jna-platform in dependencies. 它要求您在依赖项中具有jnajna-platform

This method should be called after drawing when the screen is turned off (it is another problem how to detect it). 屏幕关闭后,绘制后应调用此方法(这是检测它的另一个问题)。 As my application rarely draws automatically (without user input), I have placed its call after every drawing happening automatically. 由于我的应用程序很少自动绘制(没有用户输入),因此我在每次自动绘制之后都放置了它的调用。

It works in Win7. 它适用于Win7。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 屏幕关闭时,OnPause返回NullPointerException - OnPause return NullPointerException when screen is turned off 当屏幕关闭时,Bluetoothlescanner 停止扫描或扫描频率降低 - Bluetoothlescanner stop scanning or scan less often when screen is turned off 应用关闭时的通知 - Notifications when the app is turned off 设备处于锁定状态且屏幕处于关闭状态时,如何运行我的应用程序? - How can I run my application when device is in locked state and screen is in turned off state? 套接字仅在防火墙关闭时有效 - Socket only works when firewall turned off 即使在Android中关闭了屏幕,如何保持应用状态? - How to keep app status even if screen is turned off in Android? 如何锁定设备,但防止屏幕在android中关闭? - how to lock device but prevent the screen to be turned off in android? Android 关闭飞行模式时应用程序崩溃 - Android App crushes when airplane mode is turned off 创建一个在 UNICODE_CASE 关闭时失败但打开时匹配的示例 - Create an example that fails if UNICODE_CASE is turned off, but matches when turned on JavaFX 绘制形状时鼠标输入问题? - JavaFX problem with mouse input when drawing shapes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM