0

Собственно, вот fxml файл

<?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>

Не видит showDialog (17 строка), хотя он реализован

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());}
    }
2
  • Именно не видит? Т.е. происходит исключение или просто ничего не происходит?
    – emre
    23 июл 2017 в 19:54
  • showDialog подсвечен красным и IntelliJ IDEA предлагает создать контроллер. Пишет или нету контроллера или неверный скрипт. Но что неверного? 24 июл 2017 в 3:33

1 ответ 1

1

Проблемы может быть 2.

  1. Контроллер лежит не по пути sample.Controller

  2. Вы импортировали java.awt.ActionEvent вместо javafx.event.ActionEvent

Соответственные решения

  1. Переместить контроллер в sample.Controller или же поменять в fxml файле путь до контроллера.
  2. Использовать правльные импорты

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.