Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to use clip method of graphicContext

2989046Jul 10 2015 — edited Jul 14 2015

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);

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 11 2015
Added on Jul 10 2015
1 comment
676 views