Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharp edges on lines and curves in JavaFX FXML-based application

Tags:

canvas

javafx

Lines drawn on JavaFX canvas has sharp minecrafty edges.

For example, I took demo code from JavaFX Canvas documentation. Here is the result from demo application:

enter image description here

And here is the result from FXML-based application:

enter image description here

Canvas is being created manually from code. At the moment of drawing it is on the stage already.

Blur effect, round line cap and round line joins doesn't help.

gcProgress.setEffect(blur);
gcProgress.setStroke(Color.ROYALBLUE);
gcProgress.setLineCap(StrokeLineCap.ROUND);
gcProgress.setLineJoin(StrokeLineJoin.ROUND);
gcProgress.setLineWidth(3);

PS Maybe it's important, the same problem with fonts: anti-aliasing seems not working. Tested on Windows and Mac.

like image 360
artplastika Avatar asked Sep 10 '16 15:09

artplastika


People also ask

Is FXML JavaFX?

JavaFX FXML is an XML format that enables you to compose JavaFX GUIs in a fashion similar to how you compose web GUIs in HTML. FXML thus enables you to separate your JavaFX layout code from the rest of your application code. This cleans up both the layout code and the rest of the application code.


1 Answers

You need to set smooth="true" on your elements.


This can also be done in the scene builder: Arc->Properties-> "Smooth" checkbox when using SceneBuilder (v8.2.0).

The result:

Here is a snippet from generated FXML file:

<Arc fill="WHITE" layoutX="71.0" layoutY="61.0" length="270.0" radiusX="30.0" radiusY="30.0" startAngle="45.0" stroke="#1500ff" strokeLineCap="ROUND" strokeType="INSIDE" strokeWidth="4.0" type="ROUND" />
<Arc fill="WHITE" layoutX="138.0" layoutY="61.0" length="270.0" radiusX="30.0" radiusY="30.0" startAngle="45.0" stroke="#1500ff" strokeLineCap="ROUND" strokeType="INSIDE" strokeWidth="4.0" type="CHORD" />
<Arc fill="WHITE" layoutX="201.0" layoutY="61.0" length="270.0" radiusX="30.0" radiusY="30.0" startAngle="45.0" stroke="#1500ff" strokeLineCap="ROUND" strokeWidth="4.0" />

<Arc fill="WHITE" smooth="false" layoutX="71.0" layoutY="133.0" length="270.0" radiusX="30.0" radiusY="30.0" startAngle="45.0" stroke="#1500ff" strokeLineCap="ROUND" strokeType="INSIDE" strokeWidth="4.0" type="ROUND" />
<Arc fill="WHITE" smooth="false" layoutX="138.0" layoutY="133.0" length="270.0" radiusX="30.0" radiusY="30.0" startAngle="45.0" stroke="#1500ff" strokeLineCap="ROUND" strokeType="INSIDE" strokeWidth="4.0" type="CHORD" />
<Arc fill="WHITE" smooth="false" layoutX="201.0" layoutY="133.0" length="270.0" radiusX="30.0" radiusY="30.0" startAngle="45.0" stroke="#1500ff" strokeLineCap="ROUND" strokeWidth="4.0" />
like image 191
Marek Avatar answered Nov 30 '22 19:11

Marek