issue drawing aligned text using TextFlow and FlowPage

我的未来我决定 提交于 2020-03-06 04:51:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!