Skip to content

Instantly share code, notes, and snippets.

@varren
Created June 20, 2015 15:59
Show Gist options
  • Save varren/aa12f1921922243a5509 to your computer and use it in GitHub Desktop.
Save varren/aa12f1921922243a5509 to your computer and use it in GitHub Desktop.
import javafx.application.Application;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.stage.Stage;
public class SomeTestClass extends Application {
private static int counter = 0;
@Override
public void start(Stage primaryStage) throws Exception {
ObservableList<String> data = FXCollections.observableArrayList();
ListView<String> list = new ListView<>(data);
new Thread(() -> {
while (true){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
String newVal = "Some text " + String.valueOf(counter++);
Platform.runLater(() -> data.add(0,newVal));
}
}).start();
Scene scene = new Scene(list);
primaryStage.setScene(scene);
primaryStage.sizeToScene();
primaryStage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment