javafx stretch an image to fill a button?

前端 未结 1 1811
时光取名叫无心
时光取名叫无心 2021-01-26 17:14

I am writing a \"Star Trek\" game for fun with Java/JavaFX. My idea is that the main game screen is an 10x10 GridPane of Buttons. All the game pieces (the Enterprise, Klingons

1条回答
  •  闹比i
    闹比i (楼主)
    2021-01-26 17:45

        btnTest.setMinSize(55, 37);
        btnTest.setMaxSize(55, 37);
    
        Image image = new Image("/view/images/someImage.png", btnTest.getWidth(), btnTest.getHeight(), false, true, true);
        BackgroundImage bImage = new BackgroundImage(image, BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, new BackgroundSize(btnTest.getWidth(), btnTest.getHeight(), true, true, true, false));
    
        Background backGround = new Background(bImage);
        btnTest.setBackground(backGround);
    

    See https://docs.oracle.com/javase/8/javafx/api/javafx/scene/layout/Background.html

    0 讨论(0)
提交回复
热议问题