使用StackPane布局来设置Scene的背景

来源:互联网 发布:mysql 数据导入mysql 编辑:程序博客网 时间:2024/06/11 00:03
package stage.background;import javafx.application.Application;import javafx.scene.Scene;import javafx.scene.layout.StackPane;import javafx.stage.Stage;public class TestStage3 extends Application {    public static void main(String[] args) {        launch(args);    }    @Override    public void start(Stage primaryStage) {        StackPane root = new StackPane();        root.setId("pane");        Scene scene = new Scene(root, 300, 250);        scene.getStylesheets().addAll(this.getClass().getResource("style.css").toExternalForm());        primaryStage.setScene(scene);        primaryStage.show();    }}

style.css

#pane{    -fx-background-image: url("background_image.jpg");    -fx-background-repeat: stretch;       -fx-background-size: 900 506;    -fx-background-position: center center;    -fx-effect: dropshadow(three-pass-box, black, 30, 0.5, 0, 0); }

运行结果如下:


转自:http://stackoverflow.com/questions/9738146/javafx-how-to-set-scene-background-image

原创粉丝点击