1

I want to set a background to a group, which is the root for the scene. I tried this code, but the image does not appear. The image all.jpg is in the same Sourcefolder than the Main.java file. Could anyone help me, thank a lot

Group root = new Group();
    String image = Main.class.getResource("all.jpg").toExternalForm();
    root.setStyle("-fx-background-image: url('" + image + "') ");
fhs14647
  • 153
  • 3
  • 15
  • I am sorry to have no direct answer, but I also struggled with the JavaFX SceneGraph, what you can consider, there are something like SKIN elements, they are just to 'collect' components and are not stylable... Maybe the group is one of those. My first approach would be to wrap the group in a pane and set the background on it. – mambax Jul 23 '15 at 07:44
  • I think this should help [How to add background colour to Group layout in JavaFX?](http://stackoverflow.com/questions/24378557/how-to-add-background-colour-to-group-layout-in-javafx) @usersWithEnoughRep: Seems to be a duplicate :) – mambax Jul 23 '15 at 07:46

1 Answers1

0

A Group does not provide the ability to set a background through CSS. You need to use something which extends from Region to do that. Probably you can use a Pane which does more or like the same thing and can be styled with a background through CSS.

If you want to see whats possible for every component the CSS reference guide is the best way.

Java FX CSS Reference Guide

NDY
  • 3,527
  • 4
  • 48
  • 63