Richard N.
Richard N.

Reputation: 87

How to .setStroke(BasicStroke)?

I've got the following problem: I want to create a new BasicStroke and set it on a Graphics2D object. This is the code I wrote for that problem:

    BasicStroke stil = new BasicStroke(zo.getLinienbreite(),
        BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
    g2d.setStroke(stil);

But next to the error that the constructor BasicStroke(float, int, int) is undefined (which actually isn't if I'm reading the documentation right), it says that "The method setStroke(Stroke) in the type Graphics2D is not applicable for the arguments (BasicStroke)".

Upvotes: 2

Views: 2404

Answers (2)

Richard N.
Richard N.

Reputation: 87

Thank you for your help. Turns out that I used com.sun.prism.BasicStroke instead of the import java.awt.BasicStroke. Thanks again!

Upvotes: 0

Anders R. Bystrup
Anders R. Bystrup

Reputation: 16060

One of the BasicStroke constructors takes a float and two int's. I'm guessing zo.getLinienbreite() is not a float, so you'll either have to explicitly cast it

BasicStroke stil = new BasicStroke( (float)zo.getLinienbreite(), ...

or change it to float in zo's class. Once that's done, the next error will disappear.

Cheers,

Upvotes: 0

Related Questions