问题
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>
When I create the action in my controller IntelliJ tells me that it is never used.
Look at the Controller displayed in my Intellij
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);
}
}
In the FXML file I get the warning that a class or interface is expected. (#btnExit
).
in the fxml file it is underlined in red color
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?
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: i am new to java and javaFX
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
回答1:
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`
Running on OS X 10.9.5
and the project JDK is Oracle 1.8u102
.
I think the U in the build version stands for "Ultimate".
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.
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.
来源:https://stackoverflow.com/questions/36186854/javafx-intellij-onaction-looks-like-its-not-covered-in-controller