我如何对齐的JTextField中的文本?文本、JTextField

2023-09-11 07:53:25 作者:追逐我的明天。

我有一个JTextField具有相当大的发展,文本但是并不像我想它。

I have a JTextField with rather big bounds, the text however does not behave like I want it to.

 _________________
|                 |
|                 |
|text             |
|                 |
|_________________|

如何将我做,所以我的文字对齐像这样

how would i do it so my text aligns like this

 _________________
|text             |
|                 |
|                 |
|                 |
|_________________|

编辑: 使用的JTextArea 固定我的问题。谢谢你。

Using JTextArea fixed my problem. Thank you.

推荐答案

使用的JTextArea 所需的垂直对齐方式。

Using JTextArea is required for vertical alignment.

的JTextField 不允许超过垂直对齐方式的控制。

JTextField does not allow for control over vertical alignment.

JTextArea myLabel = new JTextArea();

和调用:

myLabel.setHorizontalAlignment(SwingConstants.LEFT);
myLabel.setVerticalAlignment(SwingConstants.TOP);