import com.sun.javafx.perf.PerformanceTracker; import java.util.ArrayList; import java.util.List; import javafx.animation.AnimationTimer; import javafx.animation.KeyFrame; import javafx.animation.Timeline; import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.*; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.stage.Stage; import javafx.util.Callback; import javafx.util.Duration; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author inekrest */ public class TableViewMemTest extends Application { static double SCENE_WEIGHT = 800.0; static double SCENE_HEIGHT = 600.0; static int ROWS = 150; static int COLS = 30; static ObservableList> staticTableData; public void initStaticLines() { staticTableData = FXCollections.observableArrayList(); for (int row = 0; row < ROWS; row++) { List line = new ArrayList(); for (int col = 0; col <= COLS; col++) { if(col == 0) line.add((double)row); else line.add(Math.random() * 1000); } staticTableData.add(line); } } static List staticCols; public void initStaticColumns() { staticCols = new ArrayList(); for (int i = 0; i <= COLS; i++) { TableColumn col = new TableColumn("Col" + i); final int coli = i; col.setDataRetriever(new Callback, Double>() { @Override public Double call(TableColumn.CellDataFeatures p) { return ((List) p.getValue()).get(coli); } }); staticCols.add(col); } } public void getLines(ObservableList> bigData) { for (int row = 0; row < ROWS; row++) { List line = new ArrayList(); for (int col = 0; col <= COLS; col++) { if(col == 0) line.add((double)row); else line.add(Math.random() * 1000); } bigData.add(line); } } public List getColumns() { List cols = new ArrayList(); for (int i = 0; i <= COLS; i++) { TableColumn col = new TableColumn("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; } Stage stage; PerformanceTracker perfTracker; Group rootGroup; int iters=1; @Override public void start(Stage primaryStage) { stage = new Stage(); rootGroup = new Group(); Scene scene = new Scene(rootGroup, SCENE_WEIGHT, SCENE_HEIGHT); stage.setScene(scene); stage.sizeToScene(); stage.setVisible(true); perfTracker = PerformanceTracker.getSceneTracker(scene); Timeline fpsTimeline = new Timeline(); fpsTimeline.setCycleCount(Timeline.INDEFINITE); KeyFrame fpsKeyFrame = new KeyFrame(Duration.valueOf(2000), new EventHandler() { @Override public void handle(ActionEvent e) { String fpsText = String.format("FPS: %.2f", perfTracker.getInstantFPS()); System.out.println(fpsText); } }); fpsTimeline.getKeyFrames().add(fpsKeyFrame); initStaticLines(); initStaticColumns(); AnimationTimer objectsAllocator = new AnimationTimer() { boolean stop = false; @Override public void handle(long l) { //ObservableList> tableData; TableView tableView; stage.setTitle("TableView " + iters); tableView = new TableView(); //List tableCols = getColumns(); //tableView.getColumns().addAll(tableCols); tableView.getColumns().addAll(staticCols); tableView.setPrefSize(SCENE_WEIGHT, SCENE_HEIGHT); tableView.setColumnControlEnabled(true); //tableData = FXCollections.observableArrayList(); //getLines(tableData); //tableView.setItems(tableData); tableView.setItems(staticTableData); if (rootGroup.getChildren().size() == 1) { rootGroup.getChildren().remove(0); } rootGroup.getChildren().add(0, tableView); System.out.println("Created " + iters + "th TableView"); System.out.println("rootGrp size: " + rootGroup.getChildren().size()); System.gc(); try { Thread.sleep(100); } catch (Exception e) {} System.gc(); try { Thread.sleep(100); } catch (Exception e) {} iters++; } }; fpsTimeline.play(); objectsAllocator.start(); } public static void main(String[] args) { Application.launch(TableViewMemTest.class, args); } }