I like the convenience of a JOptionPane, but don't like the fact that it doesn't wrap text. So I decided to implement the answer from this question as follows:
public static void main(String[] args)
{
String text = "one two three four five six seven eight nine ten ";
text = text + text + text + text + text
JTextArea textArea = new JTextArea(text);
textArea.setColumns(30);
textArea.setLineWrap( true );
textArea.setWrapStyleWord( true );
textArea.append(text);
textArea.setSize(textArea.getPreferredSize().width, 1); //Explanation for this line in the comments of the linked thread
JOptionPane.showMessageDialog(
null, textArea, "Not Truncated!", JOptionPane.WARNING_MESSAGE);
}
This works just fine on Mac OS X:
But does not work on Windows 8 because the window does not resize as the JTextArea increases in height with more multi-lines, thus pushing the buttons out of the way:
Is there something I'm doing wrong? Does Java Swing on the two platforms behave differently? How can I fix this problem?