Java tutorial
//package com.java2s; import javax.swing.JOptionPane; public class Main { /** Create a JOptionPane instance that word-wraps its message. */ public static JOptionPane makeWordWrapJOptionPane() { // The basic problem is described in this bug report: // // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4104906 // // The workaround there requires adding a scrollbar to the // message, which I do not want to do. // I tried these solutions, but they do not work (anymore?): // // http://stackoverflow.com/questions/4330076/joptionpane-showmessagedialog-truncates-jtextarea-message // http://www.coderanch.com/t/339970/GUI/java/wrap-large-message-JOptionPane-showConfirmDialog // // Most other solutions involve manually inserting newlines. // Thankfully, this one actually does work: // // http://www.jroller.com/Fester/entry/joptionpane_with_word_wrapping @SuppressWarnings("serial") JOptionPane pane = new JOptionPane() { @Override public int getMaxCharactersPerLineCount() { return 80; } }; return pane; } }