I have an FXML file that has buttons with onMouseClicked attributes. I do not set a Controller up in the FXML because I have constructor injected data I want to provide to t
Even, I don't like those notifications. I set the controllers programatically. To disable it, you need to set the highlighting level to none. To do this, open your fxml file and at the very bottom on the right side, you will see a hector icon. Click on the hector icon and set the highlight level to none by dragging the slider.
You will need to restart the IDE for the changes to take effect. The highlighting will be set to none for that file only. Other files won't see any change in their highlighting behavior until we set their highlighting level to none again.
Use the following link, if you were unable to find hector icon. https://www.jetbrains.com/help/idea/status-bar.html
You need to add top level element fx:controller.
Lets say you have a basic fxml file with a just anchor pane with a button like the fxml below.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Button layoutX="102.0" layoutY="50.0" mnemonicParsing="false" text="Button" />
</children>
</AnchorPane>
Your top level element will be the anchor pane in this case. If you want to use action buttons like onMouseClicked
you need to tell to fxml you controller class in your top level element (in this case anchor pane) like below.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.Controller">
<children>
<Button fx:id="buttonExample" layoutX="102.0" layoutY="50.0" mnemonicParsing="false" text="Button" />
</children>
</AnchorPane>
fx:controller="com.example.Controller"
line says that my control class is Controller which is in the com.example package.
Also your elements id's should begin with fx like in the example (fx:id="buttonExample"
).