Skip to content

Instantly share code, notes, and snippets.

@madhub
Last active August 29, 2015 14:17
Show Gist options
  • Save madhub/b5aed9bd66cdb8c079db to your computer and use it in GitHub Desktop.
Save madhub/b5aed9bd66cdb8c079db to your computer and use it in GitHub Desktop.
UsingFXCollections
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
public class FxTest {
public static void main(String[] args) throws InterruptedException {
ObservableList<String> names = FXCollections.observableArrayList();
names.addListener(new ListChangeListener<String>() {
@Override
public void onChanged(Change<? extends String> c) {
System.out.println("on Changed "+c);
}
});
ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.submit(() -> {
for (int i = 0; i < 10; i++) {
System.out.println("Adding ele");
names.add("" + i);
}
});
// TimeUnit.SECONDS.sleep(10);
executorService.shutdown();
executorService.awaitTermination(10, TimeUnit.MINUTES);
System.out.println("Done");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment