Hello,
I have a requirement to clip the Text inside a rectangle I am using Canvas API. Below is the sample code. But some how the text is not getting clipped.
In SWing we just need to call the setClip method on Graphics2d object. Do we have anything similar in javafx.
public class JavafxClip extends Application{
@Override
public void start(Stage stage) throws Exception {
Group root = new Group();
Canvas canvas = new Canvas(500,500);
GraphicsContext g2d = canvas.getGraphicsContext2D();
g2d.fillText("Hello How Are you", 60, 80);
g2d.setFill(Color.GREEN);
g2d.strokeRect(50, 50, 50, 50);
root.getChildren().add(canvas);
stage.setScene(new Scene(root));
stage.show();
public static void main(String[] args) {
launch(args);