如何将TextArea文本放置在其中心?
我有一个对话框和一个 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);
}
}
我的问题是,在调用 affiche() 时,文本显示在
来自另一个表单的方法。TextArea
的顶部
那么如何在 TextArea
的中心显示文本呢?我所说的“中心”是指宽度的中心和高度的中心。我已经通过代码 chp.setAlignment(Component.CENTER);
将水平对齐方式设置为居中,所以我想知道如何设置垂直对齐方式?
I have a Dialog and a TextArea
. The TextArea
component has an alignment set to Component.CENTER
. I created a method named affiche()
which displays the 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);
}
}
My problem is that the text is displayed at the top of the TextArea
when calling the affiche()
method from another Form.
So how to display the text in the center of the TextArea
? I mean by "center" the center in the width and the center in the hight. I already set the horizontal alignement to center by the code chp.setAlignment(Component.CENTER);
, so I want to know how to set the vertical alignement ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我之前的答案是错误的,我忘记了我们现在做了什么...
TextArea 支持居中对齐,尽管它没有记录,只是将样式设置为居中对齐,并且它可以开箱即用。
My previous answer was wrong, I forgot what we did by now...
TextArea supports center alignment even though its undocumented just set the style to center align and it will work out of the box.
我在不使用 DefaultLookAndFeel 类的情况下找到了解决方案。就是这样:
所以我刚刚添加了
while
代码。它有效!I found the solution without using the DefaultLookAndFeel class. Here it is :
So I just added the
while
code. And it works !