我正在尝试设计一个弹出窗口。我设计了它,并且可以工作,但是有一个小问题。这是弹出窗口的代码的一部分:
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));
}
});
弹出窗口应在应有的状态下起作用。但是其中的内容没有完全显示。这是屏幕截图:
如何解决这个问题?
删除两行:
usrpagestage.setMaxHeight(100);
usrpagestage.setMaxWidth(300);
之后,舞台将恢复为自动调整大小以适合初始场景内容的默认行为。
不,它没有用。
是的,它根本没有用:-)
它应该已经起作用了(让舞台自动调整大小本身应该是正确的解决方案)。
由于JavaFX布局库中的错误,它无法正常工作:
您可以通过手动调用stage.sizeToScene()解决该错误。
样例代码
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);
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句