Created
April 13, 2017 09:51
-
-
Save omernaci/0e5cbd782431880b7eba836883c0d245 to your computer and use it in GitHub Desktop.
JavaFX ObservableList Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Main.java class | |
import java.util.ArrayList; | |
import java.util.List; | |
import javafx.collections.FXCollections; | |
import javafx.collections.ListChangeListener; | |
import javafx.collections.ObservableList; | |
/** | |
* | |
* @author omers | |
*/ | |
public class Main { | |
public static void main(String[] args) { | |
List<String> list = new ArrayList<String>(); | |
ObservableList<String> observableList = FXCollections.observableList(list); | |
observableList.addListener(new ListChangeListener() { | |
@Override | |
public void onChanged(ListChangeListener.Change change) { | |
System.out.println("Detected a change! "); | |
while (change.next()) { | |
System.out.println("Was added? " + change.wasAdded()); | |
System.out.println("Was removed? " + change.wasRemoved()); | |
System.out.println("Was replaced? " + change.wasReplaced()); | |
System.out.println("Was permutated? " + change.wasPermutated()); | |
} | |
} | |
}); | |
observableList.add("item one"); | |
list.add("item two"); | |
System.out.println("Size: " + observableList.size()); | |
} | |
} | |
// Output : | |
// Detected a change! | |
// Was added? true | |
// Was removed? false | |
// Was replaced? false | |
// Was permutated? false | |
// Size: 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment