解释 JavaFX 中 2D 形状的 Stroke Miter Limit 属性
javaobject oriented programmingprogramming更新于 2025/10/12 1:48:17
Stroke Miter Limit 属性指定/定义 StrokeLineJoin.MITER 样式中描边线连接的限制。您可以使用 javafx.scene.shape.Shape 类的 setStrokeMiterLimit() 方法设置此值。
此方法接受双精度值并将描边斜接限制限制为给定值。如果给定值小于 1.0。则视为 1.0。
示例
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon;
import javafx.scene.shape.StrokeLineJoin;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class StrokeMiterExample extends Application {
public void start(Stage stage) {
Font font = Font.font("verdana", FontWeight.BOLD, FontPosture.REGULAR, 12);
Text label2 = new Text("Miter Limit: 3");
label2.setFont(font);
label2.setX(50.0);
label2.setY(275.0);
Polygon shape1 = new Polygon(100.0, 50.0, 50.0, 200.0, 150.0, 200.0);
shape1.setStroke(Color.BLUE);
shape1.setStrokeWidth(20);
shape1.setStrokeLineJoin(StrokeLineJoin.MITER);
shape1.setStrokeMiterLimit(3);
Text label3 = new Text("Miter Limit: 4");
label3.setFont(font);
label3.setX(250.0);
label3.setY(275.0);
Polygon shape2 = new Polygon(300.0, 50.0, 250.0, 200.0, 350.0, 200.0);
shape2.setStroke(Color.BLUE);
shape2.setStrokeWidth(20.0);
shape2.setStrokeLineJoin(StrokeLineJoin.MITER);
shape2.setStrokeMiterLimit(4);
Text label4 = new Text("Miter Limit: 0.4");
label4.setFont(font);
label4.setX(430.0);
label4.setY(275.0);
Polygon shape3 = new Polygon(490.0, 50.0, 440, 200.0, 540.0, 200.0);
shape3.setStroke(Color.BLUE);
shape3.setStrokeWidth(20.0);
shape3.setStrokeLineJoin(StrokeLineJoin.MITER);
shape3.setStrokeMiterLimit(0.4);
//创建一个 Group 对象
Group root = new Group(label2, label3, label4, shape1, shape2, shape3);
//创建一个 scene 对象
Scene scene = new Scene(root, 595, 310);
//设置 Stage 标题
stage.setTitle("Stroke Miter Limit");
//将 scene 添加到 Stage
stage.setScene(scene);
//显示舞台的内容
stage.show();
}
public static void main(String args[]){
launch(args);
}
}
输出

相关文章
有用资源
java 参考教程 - 该教程包含有关 java 的更多信息:https://www.cainiaomax.com/java/

