如何在JavaFx中将多个TextField围成一圈

时间:2018-09-19 16:08:21

标签: javafx

我试图在JavaFX中将多个文本字段围成一圈。我可以使用StackPane在中心添加一个字段,如下面提到的帖子所述,但是无法添加多个文本字段。我尝试为此使用不同的窗格,但这没用。

添加了无效的代码。我想在圆内的任意位置添加两个文本字段。使用gridpane无效。此外,我想在网格窗格中的任何位置动态创建 x 个圆,并向圆中添加多个文本字段,是否可以使用JavaFX做到这一点?

希望我能够正确解释问题说明。任何回应表示赞赏:)

    @Override
public void start(Stage arg0) throws Exception {
    arg0.setTitle("Text Boxes In circle");
    arg0.setMaxWidth(500);

    Circle circle = createCircle(); // This function is to form a circle.
    Text text = new Text("42");
    Text text1 = new Text("36");
    text.setBoundsType(TextBoundsType.VISUAL);
    text1.setBoundsType(TextBoundsType.VISUAL);
    GridPane box = new GridPane();
    // box.setConstraints(text, 2, 0); commented this out to check if it was not
    // causing problem but still didn't work
    // box.setConstraints(text1, 2, 1);
    // box.setAlignment(Pos.CENTER); Even used this to center the gridPane didn't
    // work either.
    StackPane stack = new StackPane();
    box.getChildren().addAll(text, text1);
    stack.getChildren().addAll(box, circle);

    Scene scene = new Scene(stack);
    arg0.setScene(scene);
    arg0.show();


}

public static void main(String[] args) {
    launch(args);
}

private static Circle createCircle() {
    final Circle circle = new Circle(100);
    circle.setStroke(Color.FORESTGREEN);
    circle.setStrokeWidth(10);
    circle.setStrokeType(StrokeType.INSIDE);
    circle.setFill(Color.AZURE);
    return circle;
}

how to put a text into a circle object to display it from circle's center?

0 个答案:

没有答案