使用TextFlow和FlowPage发布图形对齐文本 [英] issue drawing aligned text using TextFlow and FlowPage
问题描述
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();
}
}
当控件刷新(之后)修改)最终像下面的截图中的SEND标签。
我做错了什么? thanx for the help
PS
可以找到相同的屏幕截图这里
PPS
ie转载与问题无关的方法 getPreferredSize
code> FlowPage 不会自己调整大小。它只是告诉布局管理员的父母数字 - 根据要求 - 它想要拥有什么大小。我不使用布局管理器,但也许它不会调整您的标签大小。您可以尝试添加
setSize(getPreferredSize());您的 setText(..)
方法中的
之前重新验证。
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
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.
这篇关于使用TextFlow和FlowPage发布图形对齐文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!