JavaFX Intellij onAction看起来像控制器没有涵盖 [英] JavaFX Intellij onAction looks like its not covered in controller

查看:525
本文介绍了JavaFX Intellij onAction看起来像控制器没有涵盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JavaFX中创建了一个简单的 Fxml 应用程序。我添加了一个带有场景构建器的按钮和一个名为 btnExit 的动作:
完整的FXML文件(完全简单和新鲜生成)

I created a simple Fxml application in JavaFX. I added a button with scene builder and an action called btnExit: Complete FXML file (completely simple and fresh generated)

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.GridPane?>
<GridPane alignment="center" hgap="10" vgap="10" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.65" fx:controller="sample.Controller">
   <children>
      <Button mnemonicParsing="false" text="Button" onAction="#btnExit"/>
   </children>
</GridPane>

当我在控制器中创建动作时,IntelliJ告诉我它从未使用过。

When I create the action in my controller IntelliJ tells me that it is never used.

查看我的Intellij中显示的控制器

以下是Controller类的完整代码:

Here is the complete code of the Controller class:

package sample;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;

public class Controller
{
    @FXML
    public void btnExit(ActionEvent actionEvent)
    {
        System.exit(0);
    }
}

在FXML文件中,我收到类的警告或接口是预期的。 ( #btnExit )。

In the FXML file I get the warning that a class or interface is expected. (#btnExit).

以红色加下划线

当我运行程序时,一切正常,但是看起来好像是错的。如何通过IntelliJ警告?

When I run the program it all works, but its annoying that it looks like something is wrong. How do I get past the IntelliJ warning?

这在我的所有项目中都会发生,因此我尝试通过文件>新项目创建一个全新的IntelliJ >JavaFX应用程序。
我认为我的设置或jdk有问题,但我不知道它可能是什么。

This happens in all of my projects so i tried to create a complete new with IntelliJ via "File" > "new Project" > "JavaFX Application". I think it is something wrong with my settings or jdk but i dont know what it could be.

ps:我是java和javaFX的新手

ps: i am new to java and javaFX

我已更新至intellij 2016并已重新安装:

I updated to intellij 2016 and reinstalled it already:

IntelliJ IDEA 2016.1
Build #IC-145.258, built on March 17, 2016
JRE: 1.8.0_71-b15 amd64
JVM: Java HotSpot(TM) 64-Bit Server VM by Oracle Corporation


推荐答案

我在Intellij IDE中加载了你的课程,它工作正常。 FXML文件中没有出现红色下划线,并且CMD +点击FXML中的 #btnExit 导航到控制器。作为参考,我正在运行的Idea版本是:

I loaded your classes up in my Intellij IDE and it just worked fine. No red underline occurred in the FXML file and CMD+click on #btnExit in the FXML navigated to the corresponding method definition in the Controller. For reference, the version of Idea I am running is:

IntelliJ IDEA 2016.3.1 EAP
Build #IU-163.9166.7, built on November 29, 2016
JRE: 1.8.0_112-release-408-b2 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o` 

OS X 10.9.5 上运行,项目JDK Oracle 1.8u102

Running on OS X 10.9.5 and the project JDK is Oracle 1.8u102.

我认为构建版本中的U代表Ultimate。

I think the U in the build version stands for "Ultimate".

我的猜测(而且就是这样)是FML文件和Controller文件的链接可能是一个终极功能。尝试下载终极试用版,看它是否有效。

My guess (and it is just that) is that the linking of the FML files and Controller files might be an "Ultimate" feature. Try downloading the ultimate trial version and see if it works.

尽管IDEA社区应该支持JavaFX,但只有Ultimate支持CSS解析和智能编辑,这是JavaFX开发的一个重要部分,所以Ultimate更适合JavaFX无论如何。

Even though IDEA Community is supposed to support JavaFX, only Ultimate supports CSS parsing and intelligent editing, which is an important part of JavaFX development, so Ultimate is better for JavaFX in any case.

这篇关于JavaFX Intellij onAction看起来像控制器没有涵盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆