Home >Java >javaTutorial >How to Control Text Wrapping in JOptionPane Dialogs?
When displaying error messages in Swing applications using JOptionPane, the dialog width tends to extend proportionate to the message length. This can result in excessively wide dialogs.
JOptionPane uses a JLabel to display text. Labels support HTML formatting. By setting the maximum width of the text using CSS, we can wrap the error message.
JOptionPane.showMessageDialog( this, "<html><body><p>
In the above code, the width: 200px; style attribute sets the maximum width of the error message text to 200 pixels.
For more information on using HTML in Swing components, please consult the following resources:
The above is the detailed content of How to Control Text Wrapping in JOptionPane Dialogs?. For more information, please follow other related articles on the PHP Chinese website!