我有一个 Dialog 和一个TextArea
. 该TextArea
组件的对齐方式设置为Component.CENTER
。我创建了一个名为affiche()
显示 Dialog 的方法:
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);
}
}
我的问题是从另一个表单TextArea
调用方法时,文本显示在顶部。affiche()
那么如何在中间显示文字TextArea
呢?我的意思是“居中”宽度的中心和高度的中心。我已经通过代码将水平对齐设置为居中chp.setAlignment(Component.CENTER);
,所以我想知道如何设置垂直对齐?