Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX GraphicsContext change text size

I would like to be able to change the font size and possibly the font itself before the strokeText() method is called. I can change the color but I don't see anyway to change the font.

Pane canvas = new Pane();
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.setStroke(Color.WHITE);
gc.strokeText("Hello", 1, 1);

Anyone know how to do this?

like image 858
user1958884 Avatar asked Jan 25 '13 20:01

user1958884


1 Answers

You can set the GraphicsContext's font and font size by calling the setFont method before your strokeText call.

gc.setFont(new Font(fontName, fontSize));
like image 144
jewelsea Avatar answered Oct 19 '22 17:10

jewelsea