问题
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
.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
回答1:
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.
来源:https://stackoverflow.com/questions/9395163/issue-drawing-aligned-text-using-textflow-and-flowpage