1

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.

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 :(

Here is my project (from scratch so only essentials, with the jnativehook library): 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

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)

Pengiuns
  • 131
  • 2
  • 9
  • Please post the relevant code in your question if you want some help. It isnt really inviting to download an unknown file from somewhere for bugfixing. Besides, maybe elaborate a bit more what you mean with 'update my GUI'? What GUI, and in which way 'update'? – n247s Apr 15 '17 at 21:17
  • Hi, thanks for the comment, I've added a hastebin link (would be too long to post on stackoverflow as I would need to indent 170lines as I dont know what I'm actually missing :() Also, added trying to update the jButton and jLabel color/text via hotkey. – Pengiuns Apr 15 '17 at 21:23

1 Answers1

0

You are not using the library in a Thread safe way for 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! Please see https://github.com/kwhat/jnativehook/wiki/Swing

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

Alex Barker
  • 4,316
  • 4
  • 28
  • 47