06-11-2012 04:23 PM
Hi, I have created fat labelfields by adding paddings on them and have managed to align the text to middle via DrawStyle.HCENTER.
I am wondering how I can make them vertically centered as VCENTER does not do anything.
I can think of one way to achieve what I want - by adding calculated margin to the top but this seems to be a lot more work.
Any help will be appreciated!
Solved! Go to Solution.
06-11-2012 05:13 PM
Add equal paddings on the top and the bottom. Right now, it seems you have only a bottom padding greater than zero.
Why are you saying that adding the top padding is "a lot" more work? You divide the value you are now using for the bottom padding by 2 and set top and bottom padding to that value.
06-11-2012 05:37 PM
Adding padding (or margin) will not allow the text to move to the middle of the labelfield, it will simply add space to the entire labelfield.
To correct myself on the initial post, I haven't added any any padding or margin. I made the labelfield fat by overriding preferredheight, width, and layout.
It's weird because using DrawStyle.HCENTER will center the text position within the given horizontal space of the labelfield but DrawStyle.VCENTER will not center vertically.
06-11-2012 06:41 PM
I suspect that the main problem is in your layout code. Try creating the field with USE_ALL_WDITH | USE_ALL_HEIGHT in addition to HCENTER and VCENTER and calling super.layout with the width and height calculated by you rather than the ones passed. And do not call setExtent after super.layout.
06-13-2012 05:25 PM
I solved the problem by positioning the text manually (overriding the graphics).
Thank you for your help!
06-13-2012 05:30 PM
Overriding paint? Then you should have abandoned LabelField and extended Field instead. This would be a much safer approach.
06-13-2012 05:32 PM
Paint, sorry. Yes, I'm switching to field as I type ![]()