'#FXML' not applicable to type - javafx

package sample;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import java.io.File;
import java.net.URL;
import java.util.ResourceBundle;
import
public class tGenController implements Initializable {
Controller of a fxml
#FXML
//Error appears here says "#FXML" not applicable to type
private class generatePress() {
}
#Override
public void initialize(URL url, ResourceBundle resourceBundle) {
}
}
Error msg pop up on "#FXML" says "#FXML" not applicable type.
I through I did import all the required package but that still doesn't work.

There is a bit of mistake in your code. I think generatePress() is a function and you have defined it as a class.
Try this in your controller class -
#FXML private void generatePress(){
}

I cannot put a comment as I haven't enough reputation : why does your controller implements Initializable? Isn't it more convenient for you to use this code instead?
public class tGenController extends [Root] {
// [Root] is the main tag on your FXML file
#FXML
private void generatePress() {
//XXX
}
#FXML
public void initialize() {
//XXX
}
}

Related

KeyValue class gives error in javafx? how i fix it

KeyValue class gives error in javafx? I also implements all the abstract method but still face issue?
package at_collection;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.StackPane;
import javafx.util.Duration;
import javax.xml.crypto.dsig.keyinfo.KeyValue;
public class Scene1Controller implements Initializable {
#FXML
private StackPane parent;
#FXML
private AnchorPane child1;
#FXML
private Button btn1;
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
#FXML
private void load1(ActionEvent event) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Scene2.fxml"));
Scene scene = btn1.getScene();
root.translateYProperty().set(scene.getHeight());
parent.getChildren().add(root);
Timeline timeline = new Timeline();
KeyValue kv = new KeyValue(root.translateYProperty(), 0, Interpolator.EASE_IN); // Here is the problem
KeyFrame kf = new KeyFrame(Duration.seconds(1), kv);
timeline.getKeyFrames().add(kf);
timeline.setOnFinished(t -> {
parent.getChildren().remove(child1);
});
timeline.play();
}
}
The stack trace is not print. Because of the compile-time error. i'm actually implements this "https://www.youtube.com/watch?v=cqskg3DYH8g"
Here is the output of this code
This is because of the Wrong Import "import javax.xml.crypto.dsig.keyinfo.KeyValue"
Import this one "import javafx.animation.KeyValue;"

Blank window using Javafx

I made a window by using the screen builder program, but after I run it, only a white blank window appears. I think the problem that all variables , which are lblOUTPUT, aren't assigned. I'm a beginner at Scene builder and have been really struggling with this issue because it's my first work.
FXmain
package javaapplication6;
import java.io.IOException;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
*
* #author ammar
*/
public class FXMain extends Application {
#Override
public void start(Stage stage) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("/javaapplication6/FXML.fxml"));
Scene scene = new Scene(root, 600, 400);
stage.setScene(scene);
stage.setTitle("Kilometer to miles converter");
stage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
FXMLcontroller:
enter code here
package javaapplication6;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
/**
* FXML Controller class
*
* #author ammar
*/
public class FXMLController implements Initializable {
#FXML
private Label lblOUTPUT;
#FXML
private Button btnCONVERT;
#FXML
private TextField txtKm;
/**
* Initializes the controller class.
*/
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
Ok, I solved after two hours of struggling, I just click the run button in the NetBeans (looks like a play button) and after that, right-click on the main class, then run the file, and it worked!.

chanding scene in javafx scene bulider [duplicate]

This question already has answers here:
What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?
(18 answers)
Closed 5 years ago.
I am trying to make a loading page in javafx scenebuilder but I get an error on the line rootPane.getChildren().setAll(pane),it underlines etChildren() and says it doesnt find the symbol,dont understant why that is.
package javafxapplication14;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
public class FXMLDocumentController implements Initializable {
private Label label;
private Object theStage;
private Object rootPane;
#Override
public void initialize(URL url, ResourceBundle rb) {
}
private void loadsecond(ActionEvent event) throws IOException {
AnchorPane pane=FXMLLoader.load(getClass().getResource("Second.fxml"));
rootPane.getChildren().setAll(pane);
}
}
The class Object can't handle .getChildren().

In javafx 2 when editable set to true ,onKeyPressed, OnKeyTyped are not calling Combobox?? Please guide me

Actually We need editable dropdown.so that we have made changes that setedtitable(true) and added StringConvertor.But KeyPressed and Keytyped previouly working for filter when it is not true.but now it's not calling. can anyone help me how to avoid that ? filter is not working due to keyPressed is not calling....
The way I handled this was to get the TextEditor of ComboBox and add onKeyTyped event.
Note: TextEditor is returned if the ComboBox is set to editable.
Example:
package controller;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent;
public class AddDataController implements Initializable {
#FXML
private ComboBox<String> groupName;
#Override
public void initialize(URL arg0, ResourceBundle arg1) {
groupName.setEditable(true);
TextField tf = groupName.getEditor();
tf.setOnKeyTyped(new EventHandler<KeyEvent>(){
#Override
public void handle(KeyEvent event) {
// To Do
}
});
}
}

NullPointerException in changing javaFX scene

I have two scenes in my javaFx project .. the first one Language.fxml has a button which on click changes the scene to allDevices.fxml .. but it throws NullPointerException saying "Location is required" although both of the fxml files are in the same path !!
that's my LanguageController.java
package astrolabe;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
/**
*
* #author Ahmed Fawzy
*/
public class LanguageController implements Initializable {
#FXML
private Button arabic ;
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
arabic.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
// TODO Auto-generated method stub
try{
Node node=(Node) event.getSource();
Stage stage=(Stage) node.getScene().getWindow();
Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("allDevices.fxml"));/* Exception */
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
});
}
The problem solved by adding the package name before the fxml file name !

Resources