Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to size a SmartGWT Label or HTMLFlow to fit the size of the content?

I feel like I must be doing something really stupid. What can I do to have the size of the HTMLFlow be sized base on the content? I don't need this to be done dynamically, just the first and only time it's created. Below are two ways I've tried it (with various permutations not listed) with no luck. I've also tried with a Label to no avail.

    HLayout layout = new HLayout();
    layout.setWidth100();
    layout.setHeight(25);

    HTMLFlow bodyTypeLabel = new HTMLFlow();
    bodyTypeLabel.setHeight(25);
    bodyTypeLabel.setContents(wrapFontFace("longer content", "verdana", "2"));

    HTMLFlow drinkLabel = new HTMLFlow();
    drinkLabel.setHeight(25);
    drinkLabel.setWidth(10);
    drinklabel.setAutoWidth();
    drinkLabel.setOverflow(Overflow.VISIBLE);
    drinkLabel.setContents(wrapFontFace("content2", "verdana", "2"));

Basically, with either one, it seems no matter what, the width is set to some fixed value that doesn't change.

It'll end up looking like

longer content            content2

or

longer content2
content

In that second example, 'longer content' should be on one line, as it's a separate label/htmlflow from 'content2'. So, I either get a lot of extra spacing, or word wrapping. This seems like it should be simple so could anyone help me out here? I want it to look like:

longer content content2
like image 227
AHungerArtist Avatar asked Oct 26 '25 23:10

AHungerArtist


1 Answers

Looks like this does the trick for me:

drinkLabel.setHeight(25);
drinkLabel.setWidth(10);
drinkLabel.setOverflow(Overflow.VISIBLE);
drinkLabel.setContents(wrapFontFace(drinkContent, "verdana", "2"));
drinkLabel.setWrap(false);
drinkLabel.setExtraSpace(5);

That last bit is because it seems it trims spaces from the content, grr. I wish there was some way to not have it do that.

like image 177
AHungerArtist Avatar answered Oct 29 '25 13:10

AHungerArtist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!