What is the best way to draw a crisp, opaque hairline in JavaFX 2.2?
The documentation says, that with a strokeWidth
of 0.0d
it'll be a hairline, but it's just not visible at all. Values > 0.0d and <1.0d
show lines that are pretty fine, but also don't show an opaque behaviour. When one line cuts another, the intersecting points are lighter than the rest of the line (i'd expect this behaviour from a line with some transparency). Finally, 1.0d
draws a white line with several pixels width.
That's my test code:
LineBuilder.create().startX(i*gridSize).startY(0).endX(i*gridSize).endY(height).smooth(false).stroke(Color.WHITE).strokeWidth(0.5d).fill(Color.WHITE).build();
You can use a Region subclass, such as a Pane for your Parent, with snapToPixel set to true.
Additionally, refer to the Node documentation on the co-ordinate system.
Also see the Shape documentation:
So, if you leave your Nodes in a Group or Region which does not snapToPixel, you can follow the above instructions from the Shape documentation.
Here is some sample code: