自动换行的draw2d标签

Draw2D里的Label不支持自动换行,虽然可以插入换行符手动换行。用TextFlow和适当的Layout可以实现文字的自动换行。以下代码由sean朋友贡献,原文链接

class LabelEx extends FlowPage {

    
private TextFlow contents;

    
public LabelEx() {
        
this("");
    }

    
public LabelEx(String text) {
        contents 
= new TextFlow();
        contents.setLayoutManager(
new ParagraphTextLayout(contents, ParagraphTextLayout.WORD_WRAP_SOFT));
        contents.setText(text);
        add(contents);
    }

    
public void setText(String text) {
        contents.setText(text);
    }

    
public String getText() {
        
return contents.getText();
    }
}
posted @ 2006-03-23 11:08  八进制  阅读(6308)  评论(33编辑  收藏  举报

博客已搬家:bjzhanghao.com