• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Dimensions of custom FXML component

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I created a FXML with fx:root construct and put on it for example ImageView image; The root AnchorPane has 500 x 500 dimension, and that image located in a center 250 x 250 and has width = 50 and height = 50. I can see all bounds and cooridnates in Scene Builder.
Then i need to do some calculation in a constructor based on image Width\Height and X, Y; But all of them are equals to zero.

As i understood all layouts are invalid until my component is placed into some other parent container of stage and after stage.show() method. But i need to do calculations based just on initial FXML of a component.
I found 2 ways.
The first is to surround them into Platform->runLater():

But i'm sure that this is a wrong approach, because i have to put all initialisation component logic (positioning, transitions and so on) inside that thread.

The second way is to create a method with that calculations and execute it after parent stage initialized    ShellForm.Shell.SOME_INIT_METHOD();

That also seems to be wrong, because i have to control initialization of component inner structure outside that component.

How can i get a correct dimensions of those "child" components in a constructor of my FXML component?
Posts: 6029
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would prefer the second way, even though it breaks some OO rules.  I don't know of another way.

Just a side note: I would use Platform.exit() instead of System.exit(0) as your onCloseRequest method.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!