JOptionPane の便利さは気に入っていますが、テキストが折り返されないという事実は好きではありません。そこで、この質問からの回答を次のように実装することにしました。
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);
}
これは Mac OS X で問題なく動作します。
ただし、Windows 8 では機能しません。これは、JTextArea の高さが複数行で増加してもウィンドウのサイズが変更されず、ボタンが邪魔にならないためです。
私が間違っていることはありますか?2 つのプラットフォームでの Java Swing の動作は異なりますか? この問題を解決するにはどうすればよいですか?