Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to add row to TableView

palbanJan 4 2012 — edited Jan 6 2012
Hello forum,
I need to add a row into the following TableView:
tableView = new TableView();

        tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
        tableView.setEditable(false);
        tableView.setTableMenuButtonVisible(true);


        for (int i = 0; i < counters.size() + 1; i++) {
            //We are using non property style for making dynamic table
            final int j = i;

            if (i != 0) {
                instance = new TableColumn("Interface");
                farEnd = new TableColumn("Far end");
                col = new TableColumn(counters.get(i - 1).getName());
                col.getColumns().addAll(instance, farEnd);
            } else {
                col = new TableColumn("Timestamp");
            }
            col.setPrefWidth(200);
            col.setCellValueFactory(new Callback<CellDataFeatures<ObservableList, String>, ObservableValue<String>>() {

                public ObservableValue<String> call(CellDataFeatures<ObservableList, String> param) {
                    return new SimpleStringProperty(param.getValue().get(j).toString());
                }
            });

            tableView.getColumns().add(col);
....

and with this code I populate it
while (rs.next()) {
                    //Iterate Row
                    ObservableList<String> row = FXCollections.observableArrayList();

                    Timestamp timestamp = new Timestamp(rs.getLong("timestamp"));

                    row.add(timestamp.toGMTString());

                    for (int j = 0; j < counters.size(); j++) {
                        String strCount = rs.getString(counters.get(j).getName());
                        row.addAll(strCount,strCount);

                    }

                    data.add(row);

                }

                tableView.setItems(data);
Using this code it's populating only first column (TimeStamp).

Who can help me pls?

Thanks in advanced,
palban

Edited by: palban on 4-gen-2012 2.38
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 3 2012
Added on Jan 4 2012
1 comment
411 views