使用 TextFlow 和 FlowPage 绘制对齐文本的问题

发布于 2025-01-07 19:54:22 字数 898 浏览 5 评论 0原文

我正在使用包含 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 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏の忆 2025-01-14 19:54:22

FlowPage 不会自行调整大小。它仅根据请求告诉布局管理器其父图形的大小。我不知道使用什么布局管理器,但也许它不会调整标签的大小。您可以尝试

setSize(getPreferredSize());

在重新验证之前添加 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 add

setSize(getPreferredSize());

in your setText(..) method before revalidating.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文