Actually, here is the fxml file

<?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.text.*?> <?import javafx.geometry.*?> <?import javafx.scene.control.*?> <?import java.lang.*?> <?import javafx.scene.layout.*?> <?import javafx.geometry.Insets?> <?import javafx.scene.layout.GridPane?> <?import javafx.scene.control.Button?> <?import javafx.scene.control.Label?> <VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="420.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller"> <children> <FlowPane prefHeight="60.0" prefWidth="420.0"> <children> <Button mnemonicParsing="false" onAction="#showDialog" prefWidth="100.0" text="Добавить"> <FlowPane.margin> <Insets bottom="20.0" left="20.0" right="20.0" top="20.0" /> </FlowPane.margin> </Button> <Button mnemonicParsing="false" prefWidth="100.0" text="Изменить"> <FlowPane.margin> <Insets bottom="20.0" left="20.0" right="20.0" top="20.0" /> </FlowPane.margin> </Button> <Button mnemonicParsing="false" prefWidth="100.0" text="Удалить"> <FlowPane.margin> <Insets bottom="20.0" left="20.0" top="20.0" /> </FlowPane.margin> </Button> </children> </FlowPane> <AnchorPane prefHeight="60.0"> <children> <TextField layoutX="14.0" layoutY="18.0" promptText="Введите имя" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="140.0" /> <Button layoutX="306.0" layoutY="18.0" mnemonicParsing="false" prefWidth="100.0" text="Поиск" AnchorPane.rightAnchor="20.0" /> </children> <VBox.margin> <Insets /> </VBox.margin> </AnchorPane> <AnchorPane prefHeight="420.0" VBox.vgrow="ALWAYS"> <children> <TableView layoutX="14.0" prefWidth="420.0" AnchorPane.bottomAnchor="20.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="20.0"> <columns> <TableColumn prefWidth="75.0" text="ФИО" /> <TableColumn prefWidth="75.0" text="Телефон" /> </columns> <columnResizePolicy> <TableView fx:constant="CONSTRAINED_RESIZE_POLICY" /> </columnResizePolicy> </TableView> </children> </AnchorPane> <AnchorPane prefHeight="60.0"> <children> <Label layoutX="14.0" layoutY="21.0" text="Количество контактов:" AnchorPane.bottomAnchor="20.0" AnchorPane.leftAnchor="20.0" /> </children> </AnchorPane> </children> </VBox> 

Does not see showDialog (17th line), although it is implemented

 public void showDialog(ActionEvent actionEvent) { try { Stage modalStage = new Stage(); Parent secRoot = FXMLLoader.load(getClass().getResource("secStage.fxml")); modalStage.setTitle("Добавление контакта"); Scene secScene = new Scene(secRoot, 380, 110); modalStage.setScene(secScene); modalStage.setResizable(false); modalStage.initModality(Modality.WINDOW_MODAL); modalStage.initOwner(((Node)actionEvent.getSource()).getScene().getWindow()); modalStage.show(); } catch(IOException e) {System.out.println(e.getCause());} } 
  • It does not see? Those. Is an exception happening or is nothing just happening? - emre
  • showDialog is highlighted in red and IntelliJ IDEA offers to create a controller. Writes whether or not the controller or the wrong script. But what is wrong? - not a Programmer

1 answer 1

Problems can be 2.

  1. The controller is not in the sample.Controller path

  2. You imported java.awt.ActionEvent instead of javafx.event.ActionEvent

Related solutions

  1. Move the controller to sample.Controller or change the path to the controller in the fxml file.
  2. Use right import