假设我有这个:
public class selezioneTipoEventoForm {
@FXML private Button eventoSportivoButton;
@FXML private Button eventoMusicaleButton;
@FXML private Button eventoTeatraleButton;
@FXML private Button eventoCinemaButton;
private formController cambiaForm;
public selezioneTipoEventoForm(formController cambiaForm){
this.cambiaForm=cambiaForm;
}
@FXML public void eventoSportivoButtonPressed(ActionEvent e){
cambiaForm.mostraFormInserisciEvento(tipologiaEnum.SPORTIVO);
}
这是我的自定义控制器,现在是当我将方法绑定到按钮时出现的FXML文件,出现此错误:
No controller specified for top level element
因为我想稍后使用数据设置控制器,所以我没有在FXML文件中设置控制器,所以在这种情况下,我需要一个名为formController
的类,并且在该类中我有以下方法:
private eventoSpecificoForm setControllerEventoSportivo(FXMLLoader loader,datiEventoController controllaDatiEvento) {
try {
eventoSportivoForm esf= new eventoSportivoForm(controllaDatiEvento);
Node root = loader.load();
formAggiuntivo.getChildren().add(root);
loader.setController(esf);
return esf;
} catch (Exception e) {}
return null;
}
有解决方案吗?吓到我了。
编辑:这是给我错误的文件fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="370.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
<children>
<JFXButton fx:id="eventoSportivoButton" buttonType="RAISED" layoutX="73.0" layoutY="59.0" onAction="#eventoSportivoButtonPressed" prefHeight="100.0" prefWidth="200.0" style="-fx-background-color: #d9663f;" text="Evento Sportivo" textFill="WHITE">
<graphic>
<ImageView fitHeight="26.0" fitWidth="39.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/icons8-soccer-ball-64.png" />
</image>
</ImageView>
</graphic>
</JFXButton>
<JFXButton fx:id="eventoMusicaleButton" buttonType="RAISED" layoutX="273.0" layoutY="59.0" prefHeight="100.0" prefWidth="200.0" style="-fx-background-color: #3fd9a5;" text="Evento Musicale" textFill="WHITE">
<graphic>
<ImageView fitHeight="26.0" fitWidth="39.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/icons8-musical-64.png" />
</image>
</ImageView>
</graphic>
</JFXButton>
<JFXButton fx:id="eventoTeatraleButton" buttonType="RAISED" layoutX="73.0" layoutY="159.0" prefHeight="100.0" prefWidth="200.0" style="-fx-background-color: #3f78da;" text="Evento Teatrale" textFill="WHITE">
<graphic>
<ImageView fitHeight="26.0" fitWidth="39.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/icons8-theatre-mask-64.png" />
</image>
</ImageView>
</graphic>
</JFXButton>
<JFXButton fx:id="eventoCinemaButton" buttonType="RAISED" layoutX="273.0" layoutY="159.0" prefHeight="100.0" prefWidth="200.0" style="-fx-background-color: #da3e3e;" text="Cinema" textFill="WHITE">
<graphic>
<ImageView fitHeight="26.0" fitWidth="39.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/icons8-film-reel-64.png" />
</image>
</ImageView>
</graphic>
</JFXButton>
</children>
</AnchorPane>
此行:
<JFXButton fx:id="eventoSportivoButton" buttonType="RAISED" layoutX="73.0" layoutY="59.0" onAction=**"#eventoSportivoButtonPressed**" prefHeight="100.0" prefWidth="200.0" style="-fx-background-color: #d9663f;" text="Evento Sportivo" textFill="WHITE">
<graphic>
“未为顶级元素指定控制器”