Skip to Main Content

why stage.show() very slow

DeepakP1987Jul 2 2020 — edited Jul 2 2020

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

*/

@SuppressWarnings("restriction")

public class HelloWorld extends Application {

  @Override

  public void start(final Stage primaryStage) throws Exception {

    VBox container = new VBox();

    ScrollPane root = new ScrollPane(container);

    root.setContent(container);

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

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

    }

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

    primaryStage.show();

  }

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

    launch(args);

  }

Comments
Post Details
Added on Jul 2 2020
2 comments
116 views