gpt4 book ai didi

java - 内联显示 javaFX gui 元素

转载 作者:行者123 更新时间:2023-12-02 13:09:01 24 4
gpt4 key购买 nike

我在寻找如何在 JavaFX gui 中的同一行中显示两个元素的答案时遇到了一些麻烦。我想在同一行中以 50% 的宽度显示单选按钮,并使用两个文本字段进行相同的操作。

我添加了部分代码:

primaryStage.setTitle("Acoustic Insulation");

ToggleGroup signalGroup = new ToggleGroup();
final RadioButton radioSweep = new RadioButton("Sweep");
radioSweep.setToggleGroup(signalGroup);
radioSweep.setStyle(" -fx-display:inline-block ");

final RadioButton radioSin = new RadioButton("Sin");
radioSin.setToggleGroup(signalGroup);
radioSin.setStyle(" -fx-display:inline-block ");

Label frequencyLabel = new Label("Frequency:");
final TextField frequencyText = new TextField();

Label timeLabel = new Label("Set time [s]:");
final TextField timeText = new TextField();

Button startBtn = new Button();
startBtn.setText("START");

和实际 View :

enter image description here

最佳答案

试试这个

    GridPane root = new GridPane();
root.setAlignment(Pos.CENTER);
root.setHgap(12);

HBox box = new HBox();
box.getChildren().addAll(radioSweep, radioSin);
box.setSpacing(50);
box.setPrefWidth(200);

HBox box1 = new HBox();
box1.getChildren().addAll(frequencyText, timeText);
box1.setSpacing(12);
box1.setPrefWidth(200);

root.add(box, 0, 0);
root.add(box1, 1, 0);

Scene scene = new Scene(root, 500, 500);
primaryStage.setScene(scene);
primaryStage.show();

关于java - 内联显示 javaFX gui 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44040621/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com