Answer the question
In order to leave comments, you need to log in
Why doesn't the javafx program work?
In controller.java:
package sample;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.input.MouseEvent;
public class Controller {
@FXML
private Button btn;
@FXML
private TextArea text;
@FXML
public void btn_click(){
text.setText("Hello World");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Button fx:id="btn" layoutX="202.0" layoutY="339.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="155.0" text="Button" onAction="#btn_click" />
<TextArea fx:id="text" layoutX="180.0" layoutY="60.0" prefHeight="200.0" prefWidth="200.0" AnchorPane.rightAnchor="220.0" />
</children>
</AnchorPane>
Answer the question
In order to leave comments, you need to log in
1. The fxml root element must contain a controller
2. If you want to access btn and text from the code, they must be public
3. The @FXML annotation over the method is optional
In this case, the program does not see the method, but the entire controller - a problem in that
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question