tag:blogger.com,1999:blog-3797530974183533967.post6423829287090458982..comments2023-10-14T01:26:54.915-07:00Comments on JavaFX Scripting: How to centre nodes using bind ??Greghttp://www.blogger.com/profile/08157749298911518596noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-3797530974183533967.post-36908252537933819652018-03-07T03:53:21.750-08:002018-03-07T03:53:21.750-08:00i, Great.. Tutorial is just awesome..It is really ...i, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from <a href="http://wisentechnologies.com/it-courses/java-training.aspx" title="Java Training in Chennai" rel="nofollow">Java Training in Chennai</a>. or learn thru <a href="http://wisenitsolutions.com/IT-Courses/Java-Training" title="Java Online Training from India" rel="nofollow">Java Online Training from India</a> . Nowadays Java has tons of job opportunities on various vertical industry.Jagna Co Kalanihttps://www.blogger.com/profile/16596446199190122028noreply@blogger.comtag:blogger.com,1999:blog-3797530974183533967.post-14896065023795612842010-09-08T05:03:33.050-07:002010-09-08T05:03:33.050-07:00Hi! I read your post and can&#39;t argue against ...Hi!<br /><br />I read your post and can&#39;t argue against it, because it works. :) However, I have a consideration you may find interesting.<br /><br />The fact is you are binding a control&#39;s layout properties. This on its own is not bad. In a project I am currently working on, we ran into a slight problem with this approach. When you have a lot of controls/shapes (in the hundres) on screen, whose layout properties are bound, you may end up with some poor performance. This is what Jim Conners has coined as &#39;bindstorm&#39;.<br /><br />The problem behind this is the way binds are treated. Any update to a variable that is bound to (like the scene size), may cause a multitude of calculations to be fired. All of these calculations happen in the event-thread and will slow down the graphical performance of your application.<br /><br />To counter this, I think it is better to allow the JavaFX platform to handle the centering of the controls. After all, they optimize the crap out of their layout containers. Updates to layouts are not performed directly after a change in sizes, but rather on the next &#39;pulse&#39;. (A puls is just before JavaFX decides to re-render the screen).<br /><br />So instead of binding, I would suggest the following piece of code, which does the same as your code, but leaves the layout to a JavaFX Stack layout container in this case.<br /><br />Stage {<br /> title: &quot;Centering Nodes&quot;<br /> var scene: Scene;<br /> scene: scene = Scene {<br /> width: 400<br /> height: 100<br /> content: Stack {<br /> layoutInfo: LayoutInfo {<br /> width: bind scene.width<br /> height: bind scene.height<br /> } // end LayoutInfo<br /> content: Text {<br /> textOrigin: TextOrigin.TOP<br /> font : Font.font(null, FontWeight.BOLD, 16)<br /> content: &quot;www.javafxscripting.blogspot.com&quot;<br /> layoutInfo: LayoutInfo {<br /> hpos: HPos.CENTER<br /> vpos: VPos.CENTER<br /> } // end LayoutInfo<br /> } // end Text<br /> } // end Stack<br /> } // end Scene<br />} // end Stage<br /><br /><br />This code only binds one variable: the Stack&#39;s size. Any layout changes caused by this will be handled by the Stack and JavaFX&#39;s optimizations. In our project, this severely reduced the slow-down when resizing the window.<br /><br />Cheers!<br /><br />--JH (www.jhkuperus.nl)Anonymoushttps://www.blogger.com/profile/01785265789277421787noreply@blogger.com