[Java FX 2] Stage with rounded corners and background image

I recently had a requirement of making the window of a Java FX application with rounded corners and a background image. It is simple making rounded corners but difficult with a background image filling the main stage.

After googling around i found the following discussion that says, it seems to be difficult or not possible with Java FX as of now.


Following is a best work-around the idea is to clip the rounded corners using setClip method of the node(in the example StackPane) :

Here is an example source code [Tested with Java FX 2.2]:


package roundedtest;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class RoundedTest extends Application {

public void start(Stage primaryStage) {

Button btn = new Button();
btn.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {

StackPane root = new StackPane();
Rectangle rect = new Rectangle(1024,768);

Scene scene = new Scene(root, 1024, 768);
primaryStage.setTitle(“Hello World!”);


public static void main(String[] args) {



-fx-background-radius: 30;
-fx-border-radius: 30;


following is is how the output looks like:


About Dominic

J for JAVA more about me : http://about.me/dominicdsouza
This entry was posted in Thechy Stuff. Bookmark the permalink.

3 Responses to [Java FX 2] Stage with rounded corners and background image

  1. Thanks for the example…it made the game I am developing a lot nicer!

  2. Marek says:

    On Linux doesn’t work.

  3. Viktor says:

    how to leave top panel to drag window, and close

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s