Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat are a line's exact dimensions in JavaFX 2?
    primarykey
    data
    text
    <p>I'm wondering about a line's exact width in JavaFX 2.1. </p> <p>Creating a straight line starting at point (10;10) and ending at point (20;10) should have an expected width of 10px. When reading the line's width a value of 11px is returned. When starting the attached example and making a screenshot you'll see - at a higher zoom level - the line has a width of 12px and a height of 2px.</p> <p>Using a <code>LineBuilder</code> does not make any difference. I event tried to apply a different <code>StrokeType</code> without success. </p> <p>Creating a square with a side length of 10 returns the expected width of 10px. </p> <ol> <li>Why does <code>line.getBoundsInLocal().getWidth()</code> return different values from those I see in the rendered result (screenshot)? </li> <li>Why is there a difference concerning width when creating lines and polygons?</li> </ol> <p><strong>Example:</strong></p> <pre><code>import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.shape.Line; import javafx.scene.shape.Polygon; import javafx.stage.Stage; public class ShapeWidthDemo extends Application { @Override public void start(Stage stage) throws Exception { Group root = new Group(); int startX = 10; int startY = 10; int length = 10; Line line = new Line(startX, startY, startX + length, startY); System.out.println("line width: " + line.getBoundsInLocal().getWidth()); //-&gt;line width: 11.0 System.out.println("line height: " + line.getBoundsInLocal().getHeight()); //-&gt;line height: 1.0 root.getChildren().add(line); int startY2 = startY + 2; Polygon polygon = new Polygon( startX, startY2, startX + 10, startY2, startX + 10, startY2 + 10, startX, startY2 + 10); System.out.println("polygon width: " + polygon.getBoundsInLocal().getWidth()); //-&gt;polygon width: 10.0 System.out.println("polygon height: " + polygon.getBoundsInLocal().getHeight()); //-&gt;polygon height: 10.0 root.getChildren().add(polygon); stage.setScene(new Scene(root, 100, 100)); stage.show(); } public static void main(String[] args) { launch(args); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload