How do I call an object an object from a .fxml file in my controller file?

john douhjyel

I am making a stopwatch program and I want to set a photo for rotation. The problem is, is that I dont know how to call the photo in the controller file. It just tells me that it cannot find symbol.

Heres the photo I want to call from my .fxml file

 <ImageView fx:id="hand">
     <image>
        <Image url="@hand.png"/>
     </image>
  </ImageView>

And heres where I call it in my controller file, but I get an error.

@FXML
 private void updateStopwatch(){
    elapsedTime++;
    Integer rotation = elapsedTime * 6;
    hand.setRotate(rotation);      


 }

Thanks for the help in advance. The error I get is the following :

hand.setRotate(rotation); 
^^^^
Cannot find symbol hand
user2651804

When you have given the fxml object you want to inject into your controller the correct property fx:id="hand" you need to declare that id as a property in your controller class.

public class MyController {
    @FXML private ImageView hand;

    private void updateStopwatch(){
        elapsedTime++;
        Integer rotation = elapsedTime * 6;
        hand.setRotate(rotation);      
    }
}

In your fxml file you must refer to the controller(MyController) by adding this attribute in root element:

fx:controller="some.package.MyController"

your fxml file may only refer to one controller.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

For loop in FXML file || How to send data from controller to fxml file?

From Dev

How do I count words from a file or string object using a nested for loop?

From Dev

How do I make the response from Python's requests package be a "file-like object"

From Dev

using javascript, angular.js, and sql.js, how do I get a file object from a url?

From Dev

how do I access the object the object i sent to the server file

From Dev

How do I call an GUI object or more from main class

From Dev

How do I read a SQLite file stored in Object Storage from a Python notebook in Spark as a Service all on Bluemix?

From Dev

How to call a function in a c++ object file from java?

From Dev

JavaFX - custom object in FXML file

From Dev

For loop in FXML file || How to send data from controller to fxml file?

From Dev

how to add an object in java lang to the fxml file

From Dev

When I attach a controller to my fxml file, I get a constructLoadException

From Dev

how do i call this javascript object from a js file

From Dev

how do I access the object the object i sent to the server file

From Dev

How do I to turn my .tar.gz file into a file-like object for shutil.copyfileobj?

From Dev

Angular JS: How do i call a second service from controller and update the DOM with returned Object

From Dev

How do I get the key and it's object from a JSON file in c# using JSON.net?

From Dev

How do I read the Json object from a rest call?

From Dev

How to call a file in controller

From Dev

In Rails 5, how do I make Rails save all my attributes in an object defined in a seed file?

From Dev

How do I call a custom method from a button in a view to delete a file associated with an object? Rails app

From Dev

How do I share object from main file to supporting file in ruby?

From Dev

How do i pass an object from jsp to controller with spring

From Dev

how do I toast array values from getter in my object?

From Dev

How do I link an object file generated from C code, a static library and a NASM generated object file?

From Dev

How do I pass data from my service object to my controller?

From Dev

Kotlin FXML file controller

From Dev

How to call an object not from a file I use require.js

From Dev

How to send object or data to controller from html file?

Related Related

  1. 1

    For loop in FXML file || How to send data from controller to fxml file?

  2. 2

    How do I count words from a file or string object using a nested for loop?

  3. 3

    How do I make the response from Python's requests package be a "file-like object"

  4. 4

    using javascript, angular.js, and sql.js, how do I get a file object from a url?

  5. 5

    how do I access the object the object i sent to the server file

  6. 6

    How do I call an GUI object or more from main class

  7. 7

    How do I read a SQLite file stored in Object Storage from a Python notebook in Spark as a Service all on Bluemix?

  8. 8

    How to call a function in a c++ object file from java?

  9. 9

    JavaFX - custom object in FXML file

  10. 10

    For loop in FXML file || How to send data from controller to fxml file?

  11. 11

    how to add an object in java lang to the fxml file

  12. 12

    When I attach a controller to my fxml file, I get a constructLoadException

  13. 13

    how do i call this javascript object from a js file

  14. 14

    how do I access the object the object i sent to the server file

  15. 15

    How do I to turn my .tar.gz file into a file-like object for shutil.copyfileobj?

  16. 16

    Angular JS: How do i call a second service from controller and update the DOM with returned Object

  17. 17

    How do I get the key and it's object from a JSON file in c# using JSON.net?

  18. 18

    How do I read the Json object from a rest call?

  19. 19

    How to call a file in controller

  20. 20

    In Rails 5, how do I make Rails save all my attributes in an object defined in a seed file?

  21. 21

    How do I call a custom method from a button in a view to delete a file associated with an object? Rails app

  22. 22

    How do I share object from main file to supporting file in ruby?

  23. 23

    How do i pass an object from jsp to controller with spring

  24. 24

    how do I toast array values from getter in my object?

  25. 25

    How do I link an object file generated from C code, a static library and a NASM generated object file?

  26. 26

    How do I pass data from my service object to my controller?

  27. 27

    Kotlin FXML file controller

  28. 28

    How to call an object not from a file I use require.js

  29. 29

    How to send object or data to controller from html file?

HotTag

Archive