java - JavaFX update textArea -


i have simple javafx application has textarea. can update content of textarea code below inside start() method:

new thread(new runnable() {      public void run() {          (int = 0; < 2000; i++) {               platform.runlater(new runnable() {                 public void run() {                     txtarea.appendtext("text\n");                 }             });         }     } }).start(); 

the code write text string textarea 2000 times. want update textarea function implemented outside of start() method.

public void appendtext(string p){     txtarea.appendtext(p); } 

this function can called arbitrary programs use javafx application update textarea. how can inside appendtext function?

you give class needs write javafx.scene.control.textarea reference class holds public void appendtext(string p) method , call it. suggest pass indication class method called, e.g.:

public class mainclass implements initializable {     @fxml     private textarea txtloggingwindow;     [...more code here...]     public void appendtext(string string, string string2) {        txtloggingwindow.appendtext("[" + string + "] - " + string2 + "\n");     } }  public class secondclass {     private mainclass main;     public secondclass(mainclass mclass) {         this.main = mclass;     }     public void callmainandwritetoarea() {         this.main.appendtext(this.getclass().getcanonicalname(), "this text goes textarea");     } } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -