/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package myjavafxapplication; import java.util.ArrayList; import java.util.List; import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.util.Callback; /** * * @author yann */ public class MyJavaFXApplication extends Application { private static int NB_COL = 30; private static int NB_LINE = 10000; /** * @param args the command line arguments */ public static void main(String[] args) { Application.launch(MyJavaFXApplication.class, args); } @Override public void start(Stage primaryStage) { primaryStage.setTitle("Hello World"); Group root = new Group(); Scene scene = new Scene(root, 1200, 550, Color.LIGHTGREEN); Button btn = new Button(); btn.setLayoutX(100); btn.setLayoutY(80); btn.setText("Hello World"); btn.setOnAction(new EventHandler() { public void handle(ActionEvent event) { System.out.println("Hello World"); } }); TableView tableView = new TableView(); tableView.setItems(getData()); tableView.getColumns().addAll(getColumns()); tableView.setLayoutX(30); tableView.setLayoutY(150); tableView.setPrefSize(1100, 300); tableView.setColumnControlEnabled(true); root.getChildren().add(btn); root.getChildren().add(tableView); primaryStage.setScene(scene); primaryStage.setVisible(true); } public ObservableList getData() { final ObservableList data = FXCollections.observableArrayList(getLines()); return data; } public List> getLines() { List> data = new ArrayList>(); for (int i = 0; i < NB_LINE; i++) { List line = new ArrayList(); for (int j = 0; j <= NB_COL; j++) { if(j == 0) line.add((double)i); else line.add(Math.random() * 1000); } data.add(line); } return data; } public List getColumns() { List cols = new ArrayList(); for (int i = 0; i <= NB_COL; i++) { TableColumn col = new TableColumn(); col.setText("Col" + i); final int coli = i; col.setDataRetriever(new Callback, Double>() { @Override public Double call(TableColumn.CellDataFeatures p) { return ((List) p.getValue()).get(coli); } }); cols.add(col); } return cols; } }