JavaFX How to set scene background image

后端 未结 4 689
梦如初夏
梦如初夏 2020-11-27 16:18

How can I set the background image of a scene?

4条回答
  •  旧巷少年郎
    2020-11-27 16:42

    I know this is an old Question

    But in case you want to do it programmatically or the java way

    For Image Backgrounds; you can use BackgroundImage class

    BackgroundImage myBI= new BackgroundImage(new Image("my url",32,32,false,true),
            BackgroundRepeat.REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT,
              BackgroundSize.DEFAULT);
    //then you set to your node
    myContainer.setBackground(new Background(myBI));
    

    For Paint or Fill Backgrounds; you can use BackgroundFill class

    BackgroundFill myBF = new BackgroundFill(Color.BLUEVIOLET, new CornerRadii(1),
             new Insets(0.0,0.0,0.0,0.0));// or null for the padding
    //then you set to your node or container or layout
    myContainer.setBackground(new Background(myBF));
    

    Keeps your java alive && your css dead..

提交回复
热议问题