N
N
Newmo2017-11-27 10:37:34
Java
Newmo, 2017-11-27 10:37:34

How to work with GUI in one thread?

I'm using global keyboard capture. I can not start from the thread, the simplest, changing the text on the button.

@Override
    public void nativeKeyReleased(NativeKeyEvent nativeKeyEvent) {
        Platform.runLater( () -> {
            if(nativeKeyEvent.getKeyCode() == NativeKeyEvent.VC_F2){
 //161               
Platform.runLater( () -> b_OpenNew.setText("2"));
            }
        });
    }

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at sample.Main.lambda$null$1(Main.java:163)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Newmo, 2017-11-29
@Newmo

Called nativeKeyPressed methods outside of start.

K
Kirill Romanov, 2017-11-27
@Djaler

First, look at what exactly you have null. There are 2 options, either this is nativeKeyEvent, or b_OpenNew

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question