Question

Am in attempt to design a pop up window. I designed it and it works, but with a small problem. This is a part of code of the pop up window :

public class Warning extends BorderPane {

public Warning() {

    setCenter(addVBox2());

}

private VBox addVBox2() {

    VBox vbox = new VBox();
    vbox.setPadding(new Insets(15,10,15,10));
    vbox.setSpacing(10);

    Label l1 = new Label("WARNING");
    l1.setFont(Font.font("Calibri", FontWeight.BOLD, 20));
    l1.setTextFill(Color.BLACK);
    l1.setUnderline(true);

    Label l2 = new Label("Try other User Name..!");
    l2.setFont(Font.font("Calibri", FontWeight.BOLD, 18));
    l2.setTextFill(Color.RED);

    vbox.getChildren().addAll(l1, l2);
    return vbox;
}

And this is how I call it :

            setEffect(new BoxBlur(5, 10, 10));
            Stage usrpagestage = new Stage();
            usrpagestage.setMaxHeight(100);
            usrpagestage.setMaxWidth(300);
            usrpagestage.initStyle(StageStyle.UTILITY);
            usrpagestage.setScene(new Scene(new Warning()));
            usrpagestage.show();

            usrpagestage.setOnCloseRequest(new EventHandler<WindowEvent>() {
                @Override
                public void handle(WindowEvent t) {
                    setEffect(new BoxBlur(0, 0, 0));

                }
            });

The pop up windows works when it is supposed to. But the contents in it is not fully displayed. This is the screen shot :

enter image description here

How to solve this issue ?

Was it helpful?

Solution

Remove the two lines:

usrpagestage.setMaxHeight(100);
usrpagestage.setMaxWidth(300);

After that, the stage will revert to its default behavior of automatically sizing to fit the initial scene content.

No, it didn't worked.

Yep, it didn't worked at all :-)

It should have worked (letting the stage autosize itself should be the correct solution).

It didn't work because of a bug in the JavaFX layout libraries:

You can workaround the bug by manually calling stage.sizeToScene().

warning

Sample Code

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.*;
import javafx.scene.web.WebView;
import javafx.stage.*;

public class WarningSample extends Application {
    @Override public void start(Stage stage) throws Exception {
        final WebView view = new WebView();
        view.getEngine().load("http://www.google.com");
        stage.setScene(new Scene(view));
        stage.show();

        Stage warningStage = new Stage();
        warningStage.initStyle(StageStyle.UTILITY);
        warningStage.setScene(new Scene(new Warning()));

        // this workaround allows the stage to be sized correctly.
        warningStage.sizeToScene();

        warningStage.show();
    }

    public static void main(String[] args) { launch(); }

    private class Warning extends VBox {
        public Warning() {
            setPadding(new Insets(15, 10, 15, 10));
            setSpacing(10);

            Label heading = new Label("WARNING");
            heading.setFont(Font.font("Calibri", FontWeight.BOLD, 20));
            heading.setTextFill(Color.BLACK);
            heading.setUnderline(true);

            Label body = new Label("Try other User Name..!");
            body.setFont(Font.font("Calibri", FontWeight.BOLD, 18));
            body.setTextFill(Color.RED);

            getChildren().addAll(heading, body);
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top