简体   繁体   English

用JNativeHook更新gui?

[英]Updating gui with JNativeHook?

I'm trying to update my GUI (for example changing text/color of jButton and jLabel via hotkey) using jnativehooks so it updates my GUI when I press a hotkey, however after hours of searching and trying, I'm still not having any luck. 我正在尝试使用jnativehooks更新我的GUI(例如通过热键更改jButton和jLabel的文本/颜色),以便在我按热键时更新我的​​GUI,但是经过数小时的搜索和尝试,我仍然没有任何运气。

I have tried revalidate/validate/repaint etc but doesn't seem to be working (its calling the hotkey f9 and running the script in that section fine as it prints out the system.out), I'm a novice so I must be missing something simple :( 我已经尝试了revalidate / validate / repaint等但似乎没有工作(它调用热键f9并在该部分中运行脚本,因为它打印出system.out),我是新手所以我必须是遗失的东西很简单:(

Here is my project (from scratch so only essentials, with the jnativehook library): https://www.dropbox.com/sh/keyp0tb2nobjg8t/AABOUQFqBWETRoX9D1vtcZe2a?dl=0 这是我的项目(从头开始,所以只有必需品,与jnativehook库): https ://www.dropbox.com/sh/keyp0tb2nobjg8t/AABOUQFqBWETRoX9D1vtcZe2a?dl =0

main.java: https://www.dropbox.com/sh/keyp0tb2nobjg8t/AAA0aib7y_k0uKtJ4sbnYHN7a/src?dl=0&preview=Main.java main.java: https://www.dropbox.com/sh/keyp0tb2nobjg8t/AAA0aib7y_k0uKtJ4sbnYHN7a/src?dl=0&preview=Main.java

Any help would be appreciated. 任何帮助,将不胜感激。

Main class code for anyone that cant view dropbox: https://hastebin.com/uqarilawop.java (too many indenting to post on stackoverflow as I dont know what I'm missing) 任何无法查看dropbox的人的主类代码: https//hastebin.com/uqarilawop.java (在stackoverflow上发布太多缩进,因为我不知道我缺少什么)

You are not using the library in a Thread safe way for Swing. 您没有以Thread安全的方式使用库来进行Swing。 All UI events occur on the Swing Dispatch thread so you need to switch the native library to use Swing instead of its built in dispatcher! 所有UI事件都发生在Swing Dispatch线程上,因此您需要切换本机库以使用Swing而不是内置的调度程序! Please see https://github.com/kwhat/jnativehook/wiki/Swing 请参阅https://github.com/kwhat/jnativehook/wiki/Swing

// Set the event dispatcher to a swing safe executor service. GlobalScreen.setEventDispatcher(new SwingDispatchService());

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM