0

I need to transmit Strings to Main thread (there is GUI) to add them to javafx' TextFlow.

In the background thread's run(), reader waits strings from JSch channel. On new stings it must transmit them to main thread. So main thread can't wait data from background thread (as it is GUI thread), and background thread must send some event with new Strings.

Another trouble, that in application can be, for example, 4 background threads, that reads some data from JSch channel and send it to one window to show.

Neka
  • 1,574
  • 4
  • 22
  • 36

1 Answers1

0

To transmit data to the GUI thread,use Platfotm.runLater() method

Platform.runLater(() -> {
        /*send your data from here*/
    });

Platform.runLater makes you modify the GUI thread from other threads, It has a swing equivalent of SwingUtilities.invokeLater

Collins Abitekaniza
  • 4,496
  • 2
  • 28
  • 43
  • After some reading, I still cannot understand how to use runLater. Here some code for example: http://pastebin.com/Ka1S3Zui . On lines 12 and 24 should be some action. – Neka Nov 23 '15 at 06:52
  • @Neka In simple terms,`Platform.runLater` helps you modify the GUI thread from other threads – Collins Abitekaniza Nov 23 '15 at 07:02