List of usage examples for javafx.collections ObservableList add
boolean add(E e);
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<String>(); ObservableList<String> observableList = FXCollections.observableList(list); observableList.addListener(new ListChangeListener() { @Override//from www .ja v a2 s . c o m public void onChanged(ListChangeListener.Change change) { System.out.println("change!"); } }); observableList.add("item one"); list.add("item two"); System.out.println("Size: " + observableList.size()); }
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<String>(); ObservableList<String> observableList = FXCollections.observableList(list); observableList.addListener(new ListChangeListener() { @Override//from w w w .j a v a2 s . co m 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()); }
From source file:com.deicos.lince.components.SinChartComponent.java
public SinChartComponent() { NumberAxis xAxis = new NumberAxis(); xAxis.setLabel("x"); NumberAxis yAxis = new NumberAxis(); yAxis.setLabel("y"); XYChart.Series<Number, Number> series = new XYChart.Series<>(); series.setName("Sine"); ObservableList<XYChart.Data<Number, Number>> data = series.getData(); for (double x = -Math.PI; x < Math.PI; x += 0.5) { data.add(new XYChart.Data<Number, Number>(x, 10 * Math.sin(x))); }/* w w w . ja v a2 s.c o m*/ LineChart<Number, Number> lineChart = new LineChart<Number, Number>(xAxis, yAxis); lineChart.setTitle("Sine function"); lineChart.getData().add(series); getChildren().add(lineChart); }
From source file:demo.components.SinChartComponent.java
public SinChartComponent() { NumberAxis xAxis = new NumberAxis(); xAxis.setLabel("x"); NumberAxis yAxis = new NumberAxis(); yAxis.setLabel("y"); XYChart.Series<Number, Number> series = new XYChart.Series<>(); series.setName("Sine"); ObservableList<XYChart.Data<Number, Number>> data = series.getData(); for (double x = -Math.PI; x < Math.PI; x += 0.5) { data.add(new XYChart.Data<Number, Number>(x, 10 * Math.sin(x))); }//from w ww. ja v a2 s . co m LineChart<Number, Number> lineChart = new LineChart<Number, Number>(xAxis, yAxis); lineChart.setTitle("Sine function"); lineChart.getData().add(series); getChildren().add(lineChart); }
From source file:caillou.company.clonemanager.gui.customComponent.settings.SettingsController.java
@Override public void initialize(URL location, ResourceBundle resources) { languageComboBoxId.setCellFactory(new Callback<ListView<Language>, ListCell<Language>>() { @Override//from w w w .j a va2 s. c o m public ListCell<Language> call(ListView<Language> language) { return new LanguageListCell(); } }); languageComboBoxId.setButtonCell(new LanguageListCell()); Language frenchLanguage = new Language(Locale.FRENCH); Language englishLanguage = new Language(Locale.ENGLISH); ObservableList<Language> languages = FXCollections.observableArrayList(); languages.add(englishLanguage); languages.add(frenchLanguage); languageComboBoxId.setItems(languages); Locale currentLocale = SpringFxmlLoader.getLocale(); if (currentLocale.equals(Locale.FRENCH)) { languageComboBoxId.setValue(frenchLanguage); } else { languageComboBoxId.setValue(englishLanguage); } languageComboBoxId.valueProperty().addListener(new ChangeListener<Language>() { @Override public void changed(ObservableValue<? extends Language> observable, Language oldValue, Language newValue) { SpringFxmlLoader.changeLocale(newValue.getLocale()); } }); }
From source file:Person.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle(""); Group root = new Group(); Scene scene = new Scene(root, 500, 250, Color.WHITE); // create a grid pane GridPane gridpane = new GridPane(); gridpane.setPadding(new Insets(5)); gridpane.setHgap(10);//from w ww . j av a 2s . c o m gridpane.setVgap(10); ObservableList<Person> leaders = FXCollections.observableArrayList(); leaders.add(new Person("A", "B", "C")); leaders.add(new Person("D", "E", "F")); final ListView<Person> leaderListView = new ListView<Person>(leaders); leaderListView.setPrefWidth(150); leaderListView.setPrefHeight(150); // leaderListView.setCellFactory(new Callback<ListView<Person>, ListCell<Person>>() { public ListCell<Person> call(ListView<Person> param) { final Label leadLbl = new Label(); final Tooltip tooltip = new Tooltip(); final ListCell<Person> cell = new ListCell<Person>() { @Override public void updateItem(Person item, boolean empty) { super.updateItem(item, empty); if (item != null) { leadLbl.setText(item.getAliasName()); setText(item.getFirstName() + " " + item.getLastName()); tooltip.setText(item.getAliasName()); setTooltip(tooltip); } } }; // ListCell return cell; } }); // setCellFactory gridpane.add(leaderListView, 0, 1); leaderListView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Person>() { public void changed(ObservableValue<? extends Person> observable, Person oldValue, Person newValue) { System.out.println("selection changed"); } }); root.getChildren().add(gridpane); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { Group root = new Group(); Scene scene = new Scene(root, 300, 150); stage.setScene(scene);/*from w w w. j a va 2 s . com*/ stage.setTitle("Sample"); Task<ObservableList<String>> task = new Task<ObservableList<String>>() { @Override protected ObservableList<String> call() throws Exception { updateMessage("message"); ObservableList<String> results = FXCollections.observableArrayList(); for (int i = 0; i < 10; i++) { if (isCancelled()) break; results.add(""); updateProgress(i, 100); } return results; } }; task.run(); System.out.println(task.getMessage()); stage.show(); }
From source file:Main.java
private TreeItem<File> createNode(final File f) { return new TreeItem<File>(f) { private boolean isLeaf; private boolean isFirstTimeChildren = true; private boolean isFirstTimeLeaf = true; @Override/* ww w . j a v a 2 s.c o m*/ public ObservableList<TreeItem<File>> getChildren() { if (isFirstTimeChildren) { isFirstTimeChildren = false; super.getChildren().setAll(buildChildren(this)); } return super.getChildren(); } @Override public boolean isLeaf() { if (isFirstTimeLeaf) { isFirstTimeLeaf = false; File f = (File) getValue(); isLeaf = f.isFile(); } return isLeaf; } private ObservableList<TreeItem<File>> buildChildren(TreeItem<File> TreeItem) { File f = TreeItem.getValue(); if (f == null) { return FXCollections.emptyObservableList(); } if (f.isFile()) { return FXCollections.emptyObservableList(); } File[] files = f.listFiles(); if (files != null) { ObservableList<TreeItem<File>> children = FXCollections.observableArrayList(); for (File childFile : files) { children.add(createNode(childFile)); } return children; } return FXCollections.emptyObservableList(); } }; }
From source file:Main.java
private TreeItem<File> createNode(final File f) { return new TreeItem<File>(f) { private boolean isLeaf; private boolean isFirstTimeChildren = true; private boolean isFirstTimeLeaf = true; @Override//from w ww . ja v a 2 s. com public ObservableList<TreeItem<File>> getChildren() { if (isFirstTimeChildren) { isFirstTimeChildren = false; super.getChildren().setAll(buildChildren(this)); } return super.getChildren(); } @Override public boolean isLeaf() { if (isFirstTimeLeaf) { isFirstTimeLeaf = false; File f = (File) getValue(); isLeaf = f.isFile(); } return isLeaf; } private ObservableList<TreeItem<File>> buildChildren(TreeItem<File> TreeItem) { File f = TreeItem.getValue(); if (f != null && f.isDirectory()) { File[] files = f.listFiles(); if (files != null) { ObservableList<TreeItem<File>> children = FXCollections.observableArrayList(); for (File childFile : files) { children.add(createNode(childFile)); } return children; } } return FXCollections.emptyObservableList(); } }; }
From source file:Main.java
@Override public void start(Stage primaryStage) { ObservableList<String> names = FXCollections.observableArrayList(); ObservableList<String> data = FXCollections.observableArrayList(); ListView<String> listView = new ListView<String>(data); listView.setPrefSize(200, 250);//from w w w . j a v a 2s.c o m listView.setEditable(true); names.addAll("A", "B", "C", "D", "E"); data.add("Double Click to Select Value"); listView.setItems(data); listView.setCellFactory(ComboBoxListCell.forListView(names)); StackPane root = new StackPane(); root.getChildren().add(listView); primaryStage.setScene(new Scene(root, 200, 250)); primaryStage.show(); }