Search code examples
javagwtuser-interfaceresizesmartgwt

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

Solution

  • 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.