/* * 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.scene.Scene; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.layout.BorderPane; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.util.Callback; /** * @author yann */ public class MyJavaFXTableResizable 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"); BorderPane borderPane = new BorderPane(); Scene scene = new Scene(borderPane, 1200, 550, Color.LIGHTGREEN); primaryStage.setScene(scene); TableView tableView = new TableView(); tableView.setItems(getData()); tableView.getColumns().addAll(getColumns()); tableView.setColumnControlEnabled(true); borderPane.setCenter(tableView); 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; } }