首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >背景图像无法正常工作javaFX

背景图像无法正常工作javaFX
EN

Stack Overflow用户
提问于 2017-11-24 21:01:46
回答 0查看 2K关注 0票数 1

javafx的新手,我现在不能让我的图片成为我的背景,这可能是一些愚蠢的事情。这是代码。感谢您的帮助。

代码语言:javascript
复制
package game;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.scene.shape.Circle;
import javafx.scene.paint.Color;
import javafx.scene.layout.Pane;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundSize;
import javafx.scene.layout.Background;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.BackgroundRepeat;
import javafx.scene.layout.BackgroundPosition;
public class appgame extends Application {

    Button button;

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

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setTitle("Title of the Window");
        Pane p = new HBox();
        p.setPadding(new javafx.geometry.Insets(5,5,5,5));
        Image image = new Image("file:/home/rex/Documents/codes/java/bg1.jpg");

BackgroundImage backgroundImage = new BackgroundImage(image,BackgroundRepeat.REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, backgroundSize);

Background background = new Background(backgroundImage);

        Scene scene = new Scene(p, 306, 460);

        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

我无法将我的背景连接到我的场景,请有人帮我将我的图像设置为我的场景背景。目前代码只显示了一个空白的stage,没有背景图像。提前谢谢。

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47473901

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档