Forum Stats

  • 3,838,735 Users
  • 2,262,395 Discussions


why very slow

DeepakP1987 Member Posts: 3
edited Jul 2, 2020 11:31AM in JavaFX 2.0 and Later

I have a very simple application wherein i am trying to create a large number of buttons. And the more the number of buttons, the slow is the opening of window.

How to make it open faster ?

import javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.scene.control.ScrollPane;

import javafx.scene.layout.VBox;

import javafx.stage.Stage;


* @author DEU1COB



public class HelloWorld extends Application {


  public void start(final Stage primaryStage) throws Exception {

    VBox container = new VBox();

    ScrollPane root = new ScrollPane(container);


    for (int i = 0; i < 500000; i++) {

      container.getChildren().add(new Button("Hello_" + i));


    primaryStage.setScene(new Scene(root, 300.0, 250.0));;


  public static void main(final String[] args) {




  • BluShadow
    BluShadow Member, Moderator Posts: 42,132 Red Diamond
    edited Jul 2, 2020 11:24AM

    You're creating half a million buttons and each of those requires an object handle.  Yes that's going to be slow.

    So, the obvious question is Why?  What on Earth are you trying to achieve that would realistically require that?

  • DeepakP1987
    DeepakP1987 Member Posts: 3
    edited Jul 2, 2020 11:31AM

    Ok here for simplicity i have created half million buttons.

    But in my real time application approximately have more or less same number of nodes (VBox, HBox, Group, labels, Rectangle etc).

    So is there a way to overcome this issue ?