Example usage for javafx.collections FXCollections observableArrayList

List of usage examples for javafx.collections FXCollections observableArrayList

Introduction

In this page you can find the example usage for javafx.collections FXCollections observableArrayList.

Prototype

@SuppressWarnings("unchecked")
public static <E> ObservableList<E> observableArrayList() 

Source Link

Document

Creates a new empty observable list that is backed by an arraylist.

Usage

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    ObservableList<String> data = FXCollections.observableArrayList();

    ListView<String> listView = new ListView<String>(data);
    listView.setPrefSize(200, 250);//from  w  ww  .j av  a  2s .co  m

    data.addAll("A", "B", "C", "D", "E");

    listView.setItems(data);
    listView.getSelectionModel().selectedItemProperty()
            .addListener((ObservableValue<? extends String> ov, String old_val, String new_val) -> {
                System.out.println(new_val);

            });
    StackPane root = new StackPane();
    root.getChildren().add(listView);
    primaryStage.setScene(new Scene(root, 200, 250));
    primaryStage.show();
}

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);/* w ww  .  j a v  a 2s.c om*/
    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();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {

    ObservableList<String> data = FXCollections.observableArrayList();

    ListView<String> listView = new ListView<String>(data);
    listView.setPrefSize(200, 250);/*w  w  w . j  a v  a2  s . c  om*/
    listView.setEditable(true);

    data.addAll("A", "B", "C", "D", "E");

    listView.setItems(data);
    listView.setCellFactory((ListView<String> l) -> new ColorRectCell());
    StackPane root = new StackPane();
    root.getChildren().add(listView);
    primaryStage.setScene(new Scene(root, 200, 250));
    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);//ww w.j  a v a 2s  .  c om
    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 ObservableList<String> getData() {
    ObservableList<String> answer = FXCollections.observableArrayList();
    answer.addAll("Sales", "Products");
    return answer;
}

From source file:Main.java

private ObservableList<Data> getChartData() {
    ObservableList<Data> answer = FXCollections.observableArrayList();
    answer.addAll(new PieChart.Data("java", 17), new PieChart.Data("JavaFx", 31),
            new PieChart.Data("Swing", 10), new PieChart.Data("IO", 20), new PieChart.Data("NIO", 21));
    return answer;
}

From source file:Main.java

private ObservableList<Data> getChartData() {
    ObservableList<Data> answer = FXCollections.observableArrayList();
    answer.addAll(new PieChart.Data("java", 17.56), new PieChart.Data("JavaFx", 31.37));
    return answer;
}

From source file:Main.java

private ObservableList<XYChart.Series<String, Double>> getChartData() {
    double aValue = 1.56;
    double bValue = 1.06;
    ObservableList<XYChart.Series<String, Double>> answer = FXCollections.observableArrayList();
    Series<String, Double> aSeries = new Series<String, Double>();
    Series<String, Double> bSeries = new Series<String, Double>();
    aSeries.setName("a");
    bSeries.setName("b");

    for (int i = 2011; i < 2021; i++) {
        aSeries.getData().add(new XYChart.Data(Integer.toString(i), aValue));
        aValue = aValue + Math.random() - .5;
        bSeries.getData().add(new XYChart.Data(Integer.toString(i), bValue));
        bValue = bValue + Math.random() - .5;
    }//  ww w  .j  a  va  2 s . c o m
    answer.addAll(aSeries, bSeries);
    return answer;
}

From source file:testclientside.implement.implPerson.java

@Override
public ObservableList<Person> select() {
    ObservableList<Person> listData = FXCollections.observableArrayList();
    JSONArray arr;//from  w  w  w. j  a  va2  s .  c om
    String jsonStr = Service.ServiceGet("select.php");
    if (jsonStr != null) {
        layoutController.statusConnection = 1;
        try {
            JSONObject jsonObj = new JSONObject(jsonStr);
            arr = jsonObj.getJSONArray("hobi");
            for (int i = 0; i < arr.length(); i++) {
                JSONObject c = arr.getJSONObject(i);
                Person p = new Person();
                p.setId(c.getString("id"));
                p.setNama(c.getString("nama"));
                p.setHobi(c.getString("hobi"));
                listData.add(p);
            }
        } catch (JSONException e) {
        }
    } else {
        Platform.runLater(() -> {
            dialog.dialog(Alert.AlertType.ERROR, "Error Connection To Server");
        });
        layoutController.statusConnection = 0;
    }
    return listData;
}

From source file:Main.java

private ObservableList<XYChart.Series<String, Double>> getChartData() {
    double aValue = 10;
    double cValue = 20;
    ObservableList<XYChart.Series<String, Double>> answer = FXCollections.observableArrayList();
    Series<String, Double> aSeries = new Series<String, Double>();
    Series<String, Double> cSeries = new Series<String, Double>();
    aSeries.setName("a");
    cSeries.setName("C");

    for (int i = 2001; i < 2021; i++) {
        aSeries.getData().add(new XYChart.Data(Integer.toString(i), aValue));
        aValue = aValue + Math.random() * 100 - 50;
        cSeries.getData().add(new XYChart.Data(Integer.toString(i), cValue));
        cValue = cValue + Math.random() * 100 - 50;
    }/*from  ww  w .j av  a 2  s  .  com*/
    answer.addAll(aSeries, cSeries);
    return answer;
}