Skip to content

Instantly share code, notes, and snippets.

@KowalczykBartek
Last active December 18, 2015 23:39
Show Gist options
  • Save KowalczykBartek/5863075 to your computer and use it in GitHub Desktop.
Save KowalczykBartek/5863075 to your computer and use it in GitHub Desktop.
javafx sample
public class JavafxSampleLIST extends Application {
ListView<String> list = new ListView<>();
ObservableList<String> items = FXCollections.observableArrayList();
@Override
public void start(Stage primaryStage) {
StackPane root = new StackPane();
root.getChildren().add(list);
Scene scene = new Scene(root, 400,400);
primaryStage.setTitle("I can use JavaFX LIST");
primaryStage.setScene(scene);
primaryStage.show();
Thread t = new Thread(new MessageLoop());
t.start();
}
private class MessageLoop implements Runnable{
@Override
public void run() {
for(int i=0; i<10; i++){
items.add(Integer.toString(i));
}
Platform.runLater(new Runnable() {
@Override public void run() {
list.setItems(items);
}
});
}
}
public static void main(String[] args) {
launch(args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment