Creating Visual Effects in JavaFX

Previous
Next

5 Creating an Inner Shadow

An inner shadow is an effect that renders a shadow inside the edges of the given content with the specified color, radius, and offset.

Figure 5-1 shows plain text and the same text with the inner shadow effect applied.

Example 5-1 shows how to create an inner shadow on text.

Example 5-1 Inner Shadow

 static Node innerShadow() {
        InnerShadow is = new InnerShadow();
        is.setOffsetX(2.0f);
        is.setOffsetY(2.0f);
 
        Text t = new Text();
        t.setEffect(is);
        t.setX(20);
        t.setY(100);
        t.setText("Inner Shadow");
        t.setFill(Color.RED);
        t.setFont(Font.font("null", FontWeight.BOLD, 80));
 
        t.setTranslateX(300);
        t.setTranslateY(300);
 
        return t;
    }
Previous
Next