76

I have an element with the ID history type of TableView. How can I find and access this object if I have the instance of Scene scene?

Tower
  • 98,741
  • 129
  • 357
  • 507

1 Answers1

142

Try

TableView tb = (TableView) scene.lookup("#history");
Uluk Biy
  • 48,655
  • 13
  • 146
  • 153
  • 5
    A pound sign is required when looking up an id. So it should look like this: scene.lookup("#history"); – Orbiting Eden Jun 11 '13 at 21:52
  • 2
    @Uluk Biy can you update your answer with as TableView tb = (TableView) scene.lookup("#history"); so that others will easily understand by seeing the answer. Thank you. – AJJ Oct 30 '13 at 10:44
  • 9
    There is one important thing. This will work **after** you will invoke ```primaryStage.show()``` – MAGx2 May 30 '17 at 10:33
  • 1
    @MAGx2 _This will work after you will invoke primaryStage.show()_ as a general statement, that's not quite right (depends on how the nodes are injected - see https://stackoverflow.com/questions/68475291/javafx-finding-node-by-id) – kleopatra Jul 22 '21 at 10:20