Any hints on what black magic is needed to make the JTextAreaS
shrink properly the way they already properly grows on resize ? I tried every combination of setting preferred size and implementing Scrollable
on various things as indicated by different pieces of documentation and other SO answers without seeing any change.
The 'extra' JPanelS
are not junk, I just cut out the other stuff in them to produce a more readable test case:
public class WeirdShrinking {
public static void main(String[] args) {
JDialog jDialog = new JDialog((JFrame) null, true);
JPanel content = (JPanel) jDialog.getContentPane();
JPanel wrapper = new JPanel();
wrapper.setLayout(new MigLayout("wrap 1", "[grow]", ""));
for (int i = 0; i < 5; i++) {
JPanel panel = new JPanel();
panel.setLayout(new MigLayout("", "[grow]", ""));
JTextArea description = new JTextArea();
description.setEditable(false);
description.setOpaque(false);
description.setLineWrap(true);
description.setWrapStyleWord(true);
description.setFont(new Font("Arial", Font.PLAIN, 12));
description
.setText("Lorem ipsum ddsfolor sit amet, consectetur adipiscing elit. Curabitur viverra vehicula fermentum. Sed ac libero ut massa aliquam ornare. Nunc porttitor interdum turpis, porta viverra purus aliquam quis. In dignissim faucibus nunc, non iaculis sapien. In rutrum eleifend pharetra. Aliquam velit dui, pulvinar ut est ut, sagittis congue ligula. Etiam tincidunt varius consequat.");
panel.add(description, "growx");
wrapper.add(panel, "growx, wrap");
}
content.add(new JScrollPane(wrapper, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
jDialog.setSize(300, 200);
jDialog.setVisible(true);
}
}