Thursday Jul 23, 2009

JavaFX - Use Layout!


Update: Also refer to "How to Layout" post..

This post is to remind myself that my first preference must be to use layout, LayoutInfo and layout related attributes such as Node.layoutBounds, Node.layoutX, and Node.layoutY instead of Node.boundsInLocal, Node.translateX and Node.translateY. Amy Fowler, Baechul and Jonathan Giles had discussed about this in detail.

Earlier I was using translateX, translateY and boundsInLocal for layout of node. So when should we use layoutBounds, boundsInLocal and boundsInParent? Amy Fowler's blog has a diagram which shows difference between these attributes.

If the node does not use effect, opacity or clip, use layoutBounds to find the bounds of node. In this case layoutBounds and boundsInLocal will be same. If the node has one or more of those attributes set, then use boundsInLocal. Use boundsInParent only if some transformation attributes such as translateX, translateY, scaleX, scaleY, layoutX, layoutY etc is set and we need the bounds which includes these transformations.

Try your best not to use boundsInScene. Luckily the attribute is removed and a new method - localToScene(localBounds: Bounds) is provided. Using bounds with respect to scene complicates the computation of bounds and has major impact on performance.

In short we may mostly require just layoutX, layoutY and layoutBounds to layout a component. Use transformation attributes such as translateX, translateY etc for animation as mentioned in my previous blog. You may also be interested in related discussion happening at fxexperience.com and more layouts from JFXtras.

Now I won't forget this! How about you?

More information about JavaFX 1.2 Layout available here


<script type="text/javascript">var dzone_style = '2';</script> <script language="javascript" src="/rakeshmenonp/resource/UseLayout/zoneit.js"></script>

About


The views expressed on this blog are my own and do not necessarily reflect that of my organization

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today