【发布时间】:2014-04-02 19:37:02
【问题描述】:
我有以下代码:
public class LobbyView extends JPanel
{
this.setLayout(new MigLayout());
private final JTextArea chatWindowMessage = new JTextArea();
private final JScrollPane chatWindow = new JScrollPane(chatWindowMessage);
LobbyView(Window sentWindow)
{
chatWindow.setViewportView(chatWindowMessage);
chatWindow.setPreferredSize(new Dimension(300, 300));
chatWindow.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
chatWindowMessage.setLineWrap(true);
chatWindowMessage.append("test" + "\n");
chatWindowMessage.append("test 2" + "\n");
this.add(chatWindow, "pos 180px 75px");
this.add(chatMessage, "pos 180px 380px");
}
}
代码生成以下 JScrollPane:
如何强制 JTextArea 到 JScrollPane 的底部,使其看起来像这样(注意,我使用 MigLayout):
【问题讨论】:
-
textarea 的borderlayout 和所有嵌套在borderlayout 中心的其余部分很酷吗?
标签: java swing jscrollpane jtextarea