Java me 如何将TextArea文本放置在其中心?

Java me 如何将TextArea文本放置在其中心?,java-me,lwuit,lwuit-textarea,Java Me,Lwuit,Lwuit Textarea,我有一个对话框和一个TextArea。TextArea组件的对齐设置为component.CENTER。我创建了一个名为affiche()的方法,该方法显示对话框: public class Alert extends Dialog { private TextArea chp; private Command[] comms; public Alert(String text, Command[] comms) { super();

我有一个对话框和一个
TextArea
TextArea
组件的对齐设置为
component.CENTER
。我创建了一个名为
affiche()
的方法,该方法显示对话框:

public class Alert extends Dialog {
    private TextArea chp;
    private Command[] comms;
    public Alert(String text, Command[] comms)
    {
        super();
        this.comms = comms;
        setAutoDispose(true);
        for (int c=0; c<comms.length; c++)
            addCommand(comms[c]);
        chp = new TextArea(text);
        chp.setAlignment(Component.CENTER);
        chp.setEditable(false);
        chp.getSelectedStyle().setBorder(null);
        chp.getUnselectedStyle().setBorder(null);
        chp.getSelectedStyle().setBgColor(this.getStyle().getBgColor());
        chp.getUnselectedStyle().setBgColor(this.getStyle().getBgColor());
        chp.setRowsGap(3);
    }
    public Command affiche()
    {
        return show(null, chp, comms);
    }
}
“公共类警报扩展”对话框{ 私家区卫生防护中心; 专用命令[]通信; 公共警报(字符串文本,命令[]命令) { 超级(); this.comms=comms; setAutoDispose(true);
因为(int c=0;c我以前的答案是错的,我忘了我们现在做了什么


TextArea支持居中对齐,即使它的未文档化设置只是将样式设置为居中对齐,而且它将开箱即用。

我在不使用DefaultLookAndFeel类的情况下找到了解决方案。它是:

public class Alert extends Dialog {
    private TextArea chp;
    private Command[] comms;
    public Alert(String text, Command[] comms)
    {
        super();
        this.comms = comms;
        setAutoDispose(true);
        for (int c=0; c<comms.length; c++)
            addCommand(comms[c]);

        chp = new TextArea();
        chp.setAlignment(Component.CENTER);
        chp.setEditable(false);
        chp.getSelectedStyle().setBorder(null);
        chp.getUnselectedStyle().setBorder(null);
        chp.getSelectedStyle().setBgColor(this.getStyle().getBgColor());
        chp.getUnselectedStyle().setBgColor(this.getStyle().getBgColor());
        while (text.substring(0, (text.length()/2)+1).length() < chp.getMaxSize()/2)
        {
           text = " ".concat(text);
        }
        chp.setText(text);
    }
    public Command affiche()
    {
        return show(null, chp, comms);
    }
}
“公共类警报扩展”对话框{ 私家区卫生防护中心; 专用命令[]通信; 公共警报(字符串文本,命令[]命令) { 超级(); this.comms=comms; setAutoDispose(true);
对于(int c=0;cPlease,请给出如何实现此功能的示例。我在下面的代码中尝试过。它在project.textArea.getStyle().setAlignment(CENTER);//这里textArea是textArea的实例