FXML and controller in different packages - onAction issue button

I am new to JavaFX and am currently having some problems working with onAction events with classes in different packages.

Here is the package tree:

enter image description here

Here's some sample code that doesn't work:

<?import java.net.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>

<GridPane fx:controller="GUIController.AccueilController" 
    xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">

    ...

    <HBox spacing="10" alignment="bottom_right" 
        GridPane.columnIndex="1" GridPane.rowIndex="4">
        <Button text="Se connecter" onAction="#handleSubmitButtonAction"/>
    </HBox>

    ...

</GridPane>

      

The error is sent:

onAction="#handleSubmitButtonAction"

      

Saying: "No handler method available. Post or comment @FXML"

Here is the AccueilController.java file:

package GUIController;

import java.awt.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.text.Text;

public class AccueilController {

    @FXML private Text actiontarget;

    @FXML protected void handleSubmitButtonAction(ActionEvent event) {
        actiontarget.setText("Sign in button pressed");
    }

}

      

As you can see the @FXML tag has been added, so I don't know where the problem is. It might be a little silly, but I really can't figure it out.

By the way, without the onAction line, the code works fine.

Thanks guys!

+3


source to share


1 answer


Try replacing import java.awt.event.ActionEvent

with import javafx.event.ActionEvent

. JavaFX is probably trying to call your method with a different type of argument and cannot find a suitable overloaded method.



+4


source







All Articles