JavaFX GraphicsContext change text size


Question

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?

1
6
1/25/2013 8:45:08 PM

Accepted Answer

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));
7
1/26/2013 12:15:27 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon