栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在JavaFX中显示字符串/标签

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在JavaFX中显示字符串/标签

更换

Pane
StackPane
,并添加
sign
到它(多边形后):

public void start(Stage primaryStage) {    StackPane pane = new StackPane();    Polygon polygon = new Polygon();    polygon.setFill(javafx.scene.paint.Color.RED); //sets the color of polygon    ObservableList<Double> list = polygon.getPoints();    //create a label to display in the middle of the "stop sign" polygon shape    //This is what I need most help on    Label sign = new Label("STOP");    //sign.setStyle("-fx-text-fill: white; -fx-font-size: 3em");    sign.setAlignment(Pos.CENTER);    System.out.print(sign);    pane.getChildren().add(polygon);    pane.getChildren().add(sign);    final double WIDTH = 200, HEIGHT = 200;    double centerX = WIDTH / 2, centerY = HEIGHT / 2;    double radius = Math.min(WIDTH, HEIGHT) * 0.4;    // Add points to the polygon list    for (int i = 0; i < 6; i++) {        list.add(centerX + radius * Math.cos(2 * i * Math.PI / 6));        list.add(centerY - radius * Math.sin(2 * i * Math.PI / 6));    }    // Create a scene and place it in the stage    Scene scene = new Scene(pane, WIDTH, HEIGHT);    primaryStage.setTitle("ShowPolygon"); //Set the stage title    primaryStage.setScene(scene); //Place the scene in the stage    primaryStage.show(); //Display the stage}

关于的Javadoc

StackPane

StackPane将其子级放在从后到前的堆栈中。子级的z顺序由子级列表的顺序定义,第0个子级是底部,最后一个子级在顶部。如果已设置边框和/或填充,则将在这些插图内布置孩子。

堆栈窗格将尝试调整每个子项的大小以填充其内容区域。如果无法调整子级的大小来填充堆栈窗格(因为无法调整大小或最大尺寸阻止了它),那么它将使用alignment属性(默认值为Pos.CENTER)在区域内对其进行对齐。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/470449.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号