What contributes to a labels width?
Randahl Fink Isaksen
randahl at rockit.dk
Tue Dec 4 13:03:42 PST 2012
Font is open sans regular. Both getLayoutBounds() and getBoundsInLocal() return the same from text.
R.
On Dec 4, 2012, at 21:37 , Felipe Heidrich <felipe.heidrich at oracle.com> wrote:
> Hi Randahl,
>
> It is possible that is bug, but I would need to know the font, text, and platform before I can determine that.
>
> If the font is italic, it is possible the width you are missing is the width of the over hanging. Try using text.getBoundsInLocal() and see if that works.
>
> Regards
> Felipe
>
>
> On Dec 4, 2012, at 12:06 PM, Randahl Fink Isaksen wrote:
>
>> I am trying to calculate the width of a label before it has been laid out by simulating its width as follows:
>>
>> Text text = new Text();
>> text.setFont(label.getFont());
>> text.setText(label.getText());
>> Bounds bounds = text.getLayoutBounds();
>> double labelWidth = Math.ceil(bounds.getWidth());
>>
>> Unfortunately, it seems the label width I am predicting is a little less than the actual width of the label after layout (69 vs. 71). Could anyone enlighten me here – what else contributes to the width of the label than the font and the text?
>>
>> (or could this be attributed to rounding differences inside label and text?)
>>
>> Thanks
>>
>> Randahl
>
More information about the openjfx-dev
mailing list