我用 Java 制作了一个带有场景生成器的 Java 应用程序。它在 Java 场景构建器的预览中运行良好,但每当我按下单选按钮时,它仍然未被选中,即使在添加单选按钮之后,场景构建器中的应用程序也会滞后。我的项目提交非常接近,我的项目应用程序的每个窗口都有单选按钮,我面临着同样的问题。我的 fxml 文件的代码是,
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.ToggleGroup?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="520.0" prefWidth="750.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.project_oop.AImajorController">
<children>
<ImageView fitHeight="500.0" fitWidth="821.0" layoutX="-14.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@nextgen_blog_default.jpg" />
</image>
</ImageView>
<AnchorPane layoutX="-1.0" prefHeight="500.0" prefWidth="735.0">
<children>
<Label layoutX="8.0" layoutY="50.0" prefHeight="41.0" prefWidth="731.0" style="-fx-background-color: #f030c3;" text=" 1. I am interested in programming languages like Python, R, Julia, MATLAB, and Java.">
<font>
<Font size="14.0" />
</font>
</Label>
<RadioButton fx:id="a1_1" layoutX="44.0" layoutY="100.0" mnemonicParsing="false" onMouseClicked="#a1_1">
<toggleGroup>
<ToggleGroup fx:id="a1" />
</toggleGroup></RadioButton>
<RadioButton fx:id="a1_2" layoutX="177.0" layoutY="100.0" mnemonicParsing="false" onAction="#a1_2" toggleGroup="$a1" />
<RadioButton fx:id="a1_3" layoutX="279.0" layoutY="100.0" mnemonicParsing="false" onAction="#a1_3" toggleGroup="$a1" />
<RadioButton fx:id="a1_4" layoutX="382.0" layoutY="100.0" mnemonicParsing="false" onAction="#a1_4" toggleGroup="$a1" />
<RadioButton fx:id="a1_5" layoutX="500.0" layoutY="100.0" mnemonicParsing="false" onAction="#a1_5" toggleGroup="$a1" />
<Label layoutX="8.0" layoutY="128.0" prefHeight="41.0" prefWidth="731.0" style="-fx-background-color: #eb7b4b;" text=" I enjoy working on projects that involve computer vision, natural language processing, or machine learning.">
<font>
<Font size="14.0" />
</font>
</Label>
<RadioButton fx:id="a2_4" layoutX="382.0" layoutY="183.0" mnemonicParsing="false" onAction="#a2_4" />
<RadioButton fx:id="a2_3" layoutX="279.0" layoutY="183.0" mnemonicParsing="false" onAction="#a2_3" />
<RadioButton fx:id="a2_2" layoutX="177.0" layoutY="183.0" mnemonicParsing="false" onAction="#a2_2" />
<RadioButton fx:id="a2_1" layoutX="44.0" layoutY="183.0" mnemonicParsing="false" onAction="#a2_1" />
<RadioButton fx:id="a3_1" layoutX="44.0" layoutY="257.0" mnemonicParsing="false" onAction="#a3_1" />
<Label layoutX="10.0" layoutY="208.0" prefHeight="41.0" prefWidth="725.0" style="-fx-background-color: #77c985;" text=" I am comfortable with math and statistics.">
<font>
<Font size="14.0" />
</font>
</Label>
<Label layoutX="8.0" layoutY="291.0" prefHeight="41.0" prefWidth="731.0" style="-fx-background-color: #d1435b;" text=" I am confident that I have the ability to develop and implement machine learning algorithms.">
<font>
<Font size="14.0" />
</font>
</Label>
<Label layoutX="8.0" layoutY="447.0" prefHeight="41.0" prefWidth="731.0" />
<Label layoutX="14.0" layoutY="23.0" text="Strongly disagree" />
<Label layoutX="130.0" layoutY="23.0" text="Moderately Disagree" />
<Label layoutX="271.0" layoutY="23.0" text="Agree" />
<Label layoutX="468.0" layoutY="23.0" text="Strongly Agree" />
<Label layoutX="342.0" layoutY="23.0" text="Moderately Agree" />
<RadioButton fx:id="a2_5" layoutX="500.0" layoutY="183.0" mnemonicParsing="false" onAction="#a2_5" />
<RadioButton layoutX="382.0" layoutY="344.0" mnemonicParsing="false" />
<RadioButton layoutX="279.0" layoutY="258.0" mnemonicParsing="false" />
<RadioButton layoutX="177.0" layoutY="258.0" mnemonicParsing="false" />
<RadioButton layoutX="500.0" layoutY="257.0" mnemonicParsing="false" />
<RadioButton layoutX="390.0" layoutY="459.0" mnemonicParsing="false" />
<RadioButton layoutX="177.0" layoutY="344.0" mnemonicParsing="false" />
<RadioButton layoutX="382.0" layoutY="257.0" mnemonicParsing="false" />
<RadioButton layoutX="279.0" layoutY="344.0" mnemonicParsing="false" />
<RadioButton layoutX="500.0" layoutY="344.0" mnemonicParsing="false" />
<Label layoutX="8.0" layoutY="370.0" prefHeight="41.0" prefWidth="731.0" style="-fx-background-color: #e3d74f;" text=" For complex problems, I prefer to develop a high-level understanding of the problem before attempting a solution; ">
<font>
<Font size="14.0" />
</font>
</Label>
<RadioButton layoutX="279.0" layoutY="459.0" mnemonicParsing="false" />
<RadioButton layoutX="177.0" layoutY="459.0" mnemonicParsing="false" />
<RadioButton layoutX="44.0" layoutY="344.0" mnemonicParsing="false" />
<RadioButton layoutX="500.0" layoutY="459.0" mnemonicParsing="false" />
<Label layoutX="8.0" layoutY="410.0" prefHeight="41.0" prefWidth="731.0" style="-fx-background-color: #e3d74f;" text="for projects, I find taking breaks and restarting with fresh ideas helpful.">
<font>
<Font size="14.0" />
</font>
</Label>
<Button layoutX="627.0" layoutY="463.0" mnemonicParsing="false" prefHeight="33.0" prefWidth="95.0" style="-fx-background-color: #d11528;" text="NEXT" />
<RadioButton layoutX="52.0" layoutY="459.0" mnemonicParsing="false" />
</children>
</AnchorPane>
</children>
</AnchorPane>
我希望按钮被选中,但它们没有被选中,事实上,窗口是滞后的。
如果没有看到对应于此 FXML 文件的 Java 代码,很难诊断出确切的问题,但是有一些事情可能会导致问题。
首先,确保单选按钮具有唯一的 fx:id 值。看起来它们都有唯一的 ID(a1_1、a1_2 等),但您可能错误地复制了它们。检查它们是否都有唯一的 ID。
其次,确保您在 Java 代码中正确引用了单选按钮所属的 ToggleGroup。看起来 ToggleGroup 的 fx:id 为 a1,因此请确保您在 Java 代码中正确引用了它。
第三,您在 Scene Builder 中遇到的延迟可能是由于您的计算机资源不足。尝试关闭其他应用程序,看看是否可以提高 Scene Builder 的性能。
最后,确保您在 Java 代码中正确处理了单选按钮的 onAction 或 onMouseClicked 事件。如果您在单击单选按钮时没有做任何事情,那么它们就不会被选中。确保您正确处理事件并在 Java 代码中设置选定的单选按钮。