What contributes to a labels width?

Phil Race philip.race at oracle.com
Tue Dec 4 13:18:05 PST 2012


Yes. Take a look at LabeledSkinBase.java where you'll find that there are
a few items that are added on to get its preferred width.
The comment there says to "add on the graphic, gap and padding as 
appropriate".

-phil.

On 12/4/2012 12:33 PM, Mark Fortner wrote:
> I think the Label has an inset which may account for the difference between
> the Text width and the Label width.
>
> Mark
>
> Cheers,
>
> Mark
>
>
>
>
> On Tue, Dec 4, 2012 at 12:06 PM, Randahl Fink Isaksen<randahl at rockit.dk>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