JavaFX GraphicsContext change text size
Asked Answered
E

1

8

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?

Enthusiasm answered 25/1, 2013 at 20:45 Comment(0)
B
17

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));
Bunco answered 26/1, 2013 at 0:15 Comment(1)
Apparently I am blind as I didn't even see that. Thanks for the answer.Enthusiasm

© 2022 - 2024 — McMap. All rights reserved.