Tag Archives: javafx

Transparent background with JavaFX

Something that can be useful is to have a transparent background. For example if one wants to show several components as if they were free-floating windows while keeping them all within the same Stage.

It can be achieved by making each layer transparent (Stage, Scene, Nodes). Here is a simple example that shows how it can be done:

public class TransparentWindow extends Application {

    public void start(Stage stage) throws Exception {
        try {
            Label lbl = new Label("LABEL");
            VBox p = new VBox(lbl);

            //make the background of the label white and opaque
            lbl.setStyle("-fx-background-color: rgba(255, 255, 255, 1);");

            //add some borders to visualise the element' locations
            lbl.setBorder(new Border(new BorderStroke(Color.BLUE, BorderStrokeStyle.SOLID, null, null)));
            p.setBorder(new Border(new BorderStroke(Color.RED, BorderStrokeStyle.SOLID, null, null)));

            Scene scene = new Scene(p);

            //this is where the transparency is achieved:
            //the three layers must be made transparent
            //(i)  make the VBox transparent (the 4th parameter is the alpha)
            p.setStyle("-fx-background-color: rgba(0, 0, 0, 0);");
            //(ii) set the scene fill to transparent
            //(iii) set the stage background to transparent

        } catch (Exception e) {

    public static void main(String[] args) {

And the result looks like this (with my IDE in the background):


The next step is to add some custom buttons to allow the user to close the window (if you run the example as is you will need to kill the application).

Tagged , , ,

JavaFX 2 & Maven

One of the annoying thing with JavaFX 2 is that it is co-bundled with the JDK since Java 7u7 but is not on the classpath by default.

One way, in Netbeans, is to create a Maven JavaFX project (although I have been somewhat unlucky with that approach).

There are various alternatives proposed on the web – one that worked for me consists in playing with the pom file to include JavaFX in the classpath with:


Although this might not be the best approach, it seems to work fine.

Tagged , ,