使用TextFlow和FlowPage发布图形对齐文本 [英] issue drawing aligned text using TextFlow and FlowPage

查看:422
本文介绍了使用TextFlow和FlowPage发布图形对齐文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用包含TextFlow对象的FlowPage对象绘制一个多行文本标签。我的标签类的代码是:

  class TransitionLabel extends FlowPage {
private TextFlow content;

public TransitionLabel()
{
setForegroundColor(ColorConstants.white);
setHorizo​​ntalAligment(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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆