Answer the question
In order to leave comments, you need to log in
The onAction attribute in .fxml (javafx) does not see the method, what should I do to reach it?
Good afternoon. Please help me deal with the situation.
There is a project, for simplicity I consider one button. Prescribing an attribute to it, displays an error. Screens below.
Main
joxi.ru/vAWz671Tk9lRW2
Controller
joxi.ru/EA4L78eTD3M0JA
.fxml
joxi.ru/5mdgjbpIvD01ar
error
joxi.ru/GrqjOP6cN3xyDm
Just in case, I duplicate it with text.
Main
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, primaryStage.getWidth(), primaryStage.getHeight()));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
package sample;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
public class Controller {
@FXML
private Button button;
@FXML
public void action1 (){
button.setText("re");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
prefHeight="149.0" prefWidth="236.0" xmlns:fx="http://javafx.com/fxml/1"
xmlns="http://javafx.com/javafx/2.2" fx:controller="sample.Controller">
<children>
<Button fx:id="button" layoutX="39.0" layoutY="53.0" mnemonicParsing="false" onAction="#action1" text="Sign In" >
<font>
prefHeight="43.5" prefWidth="159.0" />
</font>
</Button>
</children>
</AnchorPane>
Answer the question
In order to leave comments, you need to log in
Decision received.
.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
prefHeight="149.0" prefWidth="236.0" xmlns:fx="http://javafx.com/fxml/1"
xmlns="http://javafx.com/javafx/2.2" fx:controller="sample.Controller">
<children>
<Button fx:id="button" layoutX="39.0" layoutY="53.0"
mnemonicParsing="false"
onAction="#actionF"
prefHeight="43.5" prefWidth="159.0"
text="Click Me!"/>
</children>
</AnchorPane>
Perhaps the error is here. Extra closing tag.
<font>
prefHeight="43.5" prefWidth="159.0" />
</font>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question