Forum Stats

  • 3,827,849 Users
  • 2,260,830 Discussions
  • 7,897,398 Comments

Discussions

why stage.show() very slow

DeepakP1987
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

*/

@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);

  }

Answers

  • BluShadow
    BluShadow Member, Moderator Posts: 41,978 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 ?