1 Reply Latest reply on May 26, 2011 2:14 PM by 416044

    Line isn't drawn at the coordinates position!

      I draw some (rectangluar) boxes and some lines to connect them - basically I draw an organigram. As long as I don't set a Stroke, everything looks fine. But the default stroke is too thick for some lines. So I set my own strokes with different widths for different lines. For lines that are thinner than the default stroke, the starting point is too low.

      I debugged my code and wrote the exact ccordinates of the boxes and the line coordinates. And all of the X/Y coordinates I set are corret - even debugged in the Java classes and see that the numbers are still correct there.

      My polylone code is from the Java Tutorial:

      final Path2D.Double polyline = new Path2D.Double(Path2D.WIND_EVEN_ODD, xCoords.length);
      // final GeneralPath polyline = new GeneralPath(Path2D.WIND_EVEN_ODD, xCoords.length);

      polyline.moveTo(xCoords[0], yCoords[0]); //move to 1st point
      for (int index = 1; index < xCoords.length; index++) { //for each point
      polyline.lineTo(xCoords[index], yCoords[index]);
      }//next point

      Stroke strokeLast = g.getStroke();
      if (stroke != null) {
      g.setStroke(stroke); //Java2D bug: depending on stroke, the drawn line may not be drawn in the correct position!

      g.setStroke(strokeLast); //restore last stroke to avoid strange effects

      I already tried some things I've read in some forum threads like diabling DircetDraw for the JVM or restore the last stroke after using a custom stroke. Also played with stroke control values (default, normalize, pure), set everything to double/Double2D/Path2D but nothing helped so far.

      I notice that the polylines with the thinner lines are connected exactly at the end point to the "child" rectangluars; but have this space to the "parent" rectangulars.

      Is there anything else, I can try?