有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java JavaFX Choicebox不填充

我试图填充一个JavaFx Choicebox,但它不显示文本,但它确实包含正确的数据。例如,如果我试图从中检索数据并将其打印出来,则表明数据在Choicebox中

@FXML
private ChoiceBox<String> shapes;

@Override
    public void start(Stage primaryStage) throws Exception {
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(getClass().getResource("/canvas.fxml"));
        Parent root = loader.load();

        Method[] m = AbstractFactory.class.getDeclaredMethods();
        ArrayList<String> shapeArrayList = new ArrayList<>();
        for(Method method : m){
            shapeArrayList.add(method.getName().substring(3));
        }
        shapes = new ChoiceBox<>();
        shapes.getItems().clear();
        shapes.getItems().addAll(FXCollections.observableArrayList(shapeArrayList));
        shapes.setValue("Test");

        primaryStage.setTitle("Paint!");
        primaryStage.setScene(new Scene(root));
        primaryStage.setResizable(false);
        primaryStage.show();
    }

FXML:

<ChoiceBox fx:id="shapes" layoutX="1.0" layoutY="174.0" prefWidth="150.0" AnchorPane.bottomAnchor="444.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="174.0" />

当我启动我的应用程序时,选择框是空的,单击时什么也不会发生


共 (0) 个答案