JavaFX + java.util.ArrayList

0

Czesc,
mam zdefiniowana prosta tabele z kolumnami Firstname, Lastname, Age. Teraz mam pytanie. Mam klase Person ktora mapuje swoje dane do nazw kolumn ale nie wiem jak spopulowac tabele z danymi z ArrayLista. Na necie, mowia tylko o ObervableList itd.

Moj kod.

 
package testingfx;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.scene.*;
import javafx.scene.control.*;
import java.util.ArrayList;


public class TestingFX extends Application {
    
    private TableView table;
    private ArrayList<Person> people = new ArrayList<>();
    
    @Override
    public void start(Stage primaryStage) {
        table = new TableView();
        TableColumn one = new TableColumn("First name");
        TableColumn two = new TableColumn("Last name");
        TableColumn three = new TableColumn("Age");
        
        table.getColumns().addAll(one, two, three);
        
        BorderPane root = new BorderPane();
        root.setBottom(table);
        
        Scene scene = new Scene(root, 500, 500);
        primaryStage.setScene(scene);
        primaryStage.show();        
    }
    
    public static void main(String[] args) {
        launch(args);
    }
}

1

Każda kolekcja w Javie, także ObservableList, ma metodę addAll i za jej pomocą możesz populować. Poza tym jest klasa FXCollections do opakowywania lub innych operacji na Listach i ObservableListach.

1 użytkowników online, w tym zalogowanych: 0, gości: 1