我需要帮助。我有一个 fxml 文件,其中包含带有按钮、表格 View 等的场景。在 Controller 中,有一种用于 ChoiseBox 之一的方法,但在构建后我看不到该方法的数据。 我尝试做另一个 Controller ,另一种方法,但没有一种方法可以帮助我
ChoiseBox 的 ID 为 -monthChoiceBox
FXML
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<Button layoutX="449.0" layoutY="15.0" mnemonicParsing="false" prefHeight="32.0" prefWidth="79.0" text="Открыть" />
<ChoiceBox fx:id="monthChoiceBox" layoutX="14.0" layoutY="15.0" prefHeight="0.0" prefWidth="247.0" />
<Button layoutX="1162.0" layoutY="626.0" mnemonicParsing="false" text="Сохранить" />
<ChoiceBox layoutX="278.0" layoutY="16.0" prefWidth="150.0" />
</children>
</AnchorPane>
Controller
// some import classes
public class Controller {
@FXML private ChoiceBox<String> monthChoiceBox;
@FXML
private void fillmonthChoiceBox() {
ObservableList<String> month = FXCollections.observableArrayList();
month.addAll("Январь", "Февраль", "Март",
"Апрель", "Май", "Июнь",
"Июль", "Август", "Сентябрь",
"Октябрь", "Ноябрь", "Декабрь");
monthChoiceBox.setItems(month);
}
}
主要
package sample;
//some import classes
public class Main extends Application{
@Override
public void start(Stage stage) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("main.fxml"));
stage.setTitle("Учет рабочего времени дежурно-диспетчерского состава");
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
最佳答案
我没有看到 fillmonthChoiceBox() 的调用。方法的 @FXM 注释用于绑定(bind)组件的处理程序。就像 onMouseClicked="#handleOnMouseClicked"一样。在这种情况下,可以使用 @FXML public voidinitialize() {} 进行数据初始化
关于java - ChoiseBox JavaFX 不显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60081902/