package com.lodh.arte.javafx; import java.util.ArrayList; import java.util.List; import javafx.application.Application; import javafx.builders.ButtonBuilder; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.layout.BorderPane; import javafx.scene.transform.Rotate; import javafx.stage.Stage; import javafx.util.Callback; // http://javafx-jira.kenai.com/browse/RT-14147 // http://javafx-jira.kenai.com/browse/RT-14266 public class MyTable1 extends Application { private static int NB_COL = 10; private static int NB_LINE = 1000; ObservableList> data = FXCollections.observableArrayList(); TableView> tableView; /** * @param args the command line arguments */ public static void main(String[] args) { Application.launch(MyTable1.class, args); } @Override public void start(Stage primaryStage) { primaryStage.setTitle(getClass().getName()); BorderPane borderPane = new BorderPane(); Scene scene = new Scene(borderPane, 300, 200, null); primaryStage.setScene(scene); tableView = new TableView>(data); tableView.getColumns().addAll(getColumns()); tableView.setColumnControlEnabled(true); borderPane.setCenter(tableView); borderPane.setTop(new ButtonBuilder().text("Populate").onAction(new EventHandler() { @Override public void handle(ActionEvent event) { data.setAll(getLines()); tableView.getTransforms().add(new Rotate(30, 50, 50)); } }).build()); primaryStage.setVisible(true); } public List> getLines() { List> data = new ArrayList>(); for (int i = 0; i < NB_LINE; i++) { List line = new ArrayList(); data.add(line); for (int j = 0; j <= NB_COL; j++) { line.add("" + (j == 0 ? (double) i : Math.random() * 1000)); } } return data; } public List> getColumns() { List> cols = new ArrayList>(); for (int i = 0; i <= NB_COL; i++) { TableColumn col = new TableColumn("Col" + i); cols.add(col); final int coli = i; col.setDataRetriever(new Callback, String>() { @SuppressWarnings("unchecked") @Override public String call(TableColumn.CellDataFeatures p) { return ((List) p.getValue()).get(coli); } }); } return cols; } }