0

i'm drawing a multiline text label using a FlowPage object that contains a TextFlow object. the code of my label class is:

class TransitionLabel extends FlowPage {
    private TextFlow content;
    
    public TransitionLabel()
    {
        setForegroundColor(ColorConstants.white);
        setHorizontalAligment(PositionConstants.CENTER);
        content = new TextFlow();
        content.setOpaque(true);
        content.setText("");
        add(content);
    }
    
    public void setText(String content)
    {
        this.content.setText(content);
        revalidate();
        repaint();
    }
    
    public String getText()
    {
        return this.content.getText();
    }
    
}

when the control is refreshed (after modification) it ends up like the SEND labels in the screenshot below messy label texts.

am i doing something wrong? thanx for the help

PS the same screenshot can be found here

PPS i edited the method getPreferredSize that was irrelevant for the problem

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
FSp
  • 1,545
  • 17
  • 37
  • Who is responsible for actually setting the size of your label? – Frettman Feb 22 '12 at 16:34
  • Actually I don't known exactly. This label is added to the figure that represent my ConnectionEditPart in the Eclipse plugin I'm writing, I don't known which object is responsible for setting the size of the label (I think the layout associated with the layout associated to FlowPage by default). Is it an important detail? Is there a way I can check and give you a more detailed answer? Also, if you ask this because of the `getPreferredSize(...)`, I should mention that I copied the snipped from a tutorial, but also removing the method the problem remains – FSp Feb 22 '12 at 23:34
  • How is the `TransitionLabel` used? as a decorator in the link? – vainolo Feb 23 '12 at 04:09

1 Answers1

0

The FlowPage doesn't resize itself. It only tells the layout manager of its parent figure - upon request - what size it would like to have. I don't what layout manager is used, but maybe it doesn't resize your label. You could try to add

setSize(getPreferredSize());

in your setText(..) method before revalidating.

Frettman
  • 2,251
  • 1
  • 13
  • 9
  • thanx for the hint. i tried it and didn't solve the problem. i don't think the problem is the size of the `FlowPage` but the fact that it shows two copies of the same content: the first is aligned LEFT and the second aligned at the CENTER, as I specified. as a sidenote: I removed the `getPreferredSize` method from the example, to simplify the problem ... – FSp Feb 23 '12 at 18:57
  • In any case, I don't think the problem is your label - mine is basically the same: a `TextFlow` in a `FlowPage`. So it has to be a problem with how it is used. If the text of the label is painted twice, maybe you added two labels? What also strikes me as odd: why isn't the first line painted twice? – Frettman Feb 24 '12 at 08:40