使用 TextFlow 和 FlowPage 绘制对齐文本的问题
我正在使用包含 TextFlow 对象的 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 标签
我做错了什么吗?感谢您的帮助
PS 可以在此处找到相同的屏幕截图
PPS 我编辑了与问题无关的方法 getPreferredSize
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
FlowPage
不会自行调整大小。它仅根据请求告诉布局管理器其父图形的大小。我不知道使用什么布局管理器,但也许它不会调整标签的大小。您可以尝试在重新验证之前添加
setText(..)
方法。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 addin your
setText(..)
method before revalidating.