• 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

JavaFX : Simply binding and property to draw rectangle

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

Firstly, sorry for my bad English.
I have a question to ask you, I try to create a simply application in JavaFX that use property and binding.
I reduce my application at the minimal for show you my problem.

I would like to put a red rectangle at the middle of borderPane, this rectangle is into an HBox (I think the problem is here) and i would like that rectangle grow up or reduce in the same time that is container (the HBox).
This is my code :

But it does'nt work... When I slowly resize my Frame, it's work, nevertheless, when I fastly resize my Frame, the rectangle is not in the middle (not the same size too) and we can see the same things when we minimize and maximize the Frame.

I don't understand why it does'nt work. So if you can help me to explain how do this for a rectangle in HBox thank you.

Thank you for your help,

Sorry for my bad english again.

Florian.
 
Rancher
Posts: 387
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My guess is that there is a time lag between when the bindings are applied and when the layout is calculated.

If you use a resizable pane rather than a rectangle and set appropriate constraints on the pane, so that it behaves and resizes like your rectangle does, then I don't see the same laggy behavior. I think that is because the pane is resized within the same layout pass as the rest of the UI whereas the bound rectangle might be resized in a subsequent layout pass, but that is just speculation.

When you use binding for layout there is a slightly recursive or iterative relationship happening, the HBox's width is calculated based upon its content width (the rectangle's width), but the content width (the rectangle's width) is calculated using a bind to the HBox's width - I'm not sure that specifying such interdependent layout rules using binding is a very good idea. As an alternative you can use resizable layout managers with constraints (as shown in the example below), or layout programatically by overriding the layoutChildren() method for Region. Over-riding layoutChildren() is the way the internal implementation of JavaFX does most of its layouts for the layout managers and controls, however there are many tricks and difficulties to doing this (such as clean handling of snapping to pixel boundaries), so implementing your own layout by over-riding layoutChildren() is an advanced topic for which there is little to no tutorials on the Internet. So I advise sticking to constraints specified using existing resizable layout managers.

reply
    Bookmark Topic Watch Topic
  • New Topic