• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dimensions of custom FXML component

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello.

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?
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic