If I use a JTextArea with MigLayout like this:
MigLayout thisLayout = new MigLayout("", "[][grow]", "[]20[]");
this.setLayout(thisLayout);
{
jLabel1 = new JLabel();
this.add(jLabel1, "cell 0 0");
jLabel1.setText("jLabel1");
}
{
jTextArea1 = new JTextArea();
this.add(jTextArea1, "cell 0 1 2 1,growx");
jTextArea1.setText("jTextArea1");
jTextArea1.setLineWrap(false);
}
then the JTextArea grows and shrinks perfectly when resizing the window. When I set the linewrap to true the JTextArea is not shrinking when I make the window smaller again.
This is because
JTextArea‘s automatically have their minimum width set anytime they resize. Details are available on the MigLayout forum. To roughly summarize, create a panel that contains theJTextAreaand gives you further control over the resize behavior. Here’s an excerpt from the above forum post:Then, wherever you would use the JTextArea, use the panel containing the text area: