Line wrap in a JTextArea causes JScrollPane to missbehave with MiGLayout

I am having trouble with the same thing as this guy:

MigLayout JTextArea is not shrinking when used with linewrap=true

and I used the solution described in one of the answers; to set the minimum size explicitly. This works fine if one places the JPanel which contains the JTextArea directly in a JFrame, and then resizes the window.

However, when placing the panel which contains the JTextArea inside a JScrollPane, the same problem occurs again. Why is this, and how can one fix it?

Cheers

EDIT: An example

public class MiGTest2 extends JFrame{   
public MiGTest2(){
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new MigLayout("fillx, debug", "[fill]"));
    JTextArea textArea  = new JTextArea();
    textArea.setLineWrap(true);
    panel.add(textArea, "wmin 10");
    //panel.add(new JTextField());
    JScrollPane scrollPane = new JScrollPane(panel);
    //add(panel);
    add(scrollPane);
    pack();
}
public static void main(String[] args){
    new MiGTest2().setVisible(true);
}
}

If you uncomment //add(panel);, and comment add(scrollPane);, shrinking the window size will also shrink the JTextArea. That is, it does not work with a JScrollPane. Also note how the layout manager seems to flip out and starts "shaking" all its contents when shrinking the size of the window after first enlarging it

5
задан Community 23 May 2017 в 12:22
поделиться