Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

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
393 views