gpt4 book ai didi

javafx - usrpagestage.initStyle(StageStyle.UTILITY) 没有完全显示内容

转载 作者:行者123 更新时间:2023-12-04 13:34:03 25 4
gpt4 key购买 nike

我正在尝试设计一个弹出窗口。我设计了它并且它可以工作,但有一个小问题。这是弹出窗口的部分代码:

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;
}

我就是这样调用它的:

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

}
});

弹出窗口按预期工作。但是里面的内容并没有完全显示出来。这是屏幕截图:

enter image description here

如何解决这个问题?

最佳答案

删除两行:

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

之后,舞台将恢复为自动调整大小以适应初始场景内容的默认行为。

No, it didn't worked.

是的,它根本不起作用:-)

它应该有效(让舞台自动调整自己应该是​​正确的解决方案)。

由于 JavaFX 布局库中的错误,它没有工作:

您可以通过手动调用 stage.sizeToScene() 来解决该错误.

warning

示例代码

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

关于javafx - usrpagestage.initStyle(StageStyle.UTILITY) 没有完全显示内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22981266/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com