Text wrap in JOptionPane?

前端 未结 2 714
情歌与酒
情歌与酒 2020-11-22 15:51

I\'m using following code to display error message in my swing application

try {
    ...
} catch (Exception exp) {
    JOptionPane.showMessageDialog(this, ex         


        
2条回答
  •  野性不改
    2020-11-22 16:12

    A JOptionPane will use a JLabel to display text by default. A label will format HTML. Set the maximum width in CSS.

    JOptionPane.showMessageDialog(
        this, 
        "

    "+exp.getMessage()+"

    ", "Error", JOptionPane.ERROR_MESSAGE);

    More generally, see How to Use HTML in Swing Components, as well as this simple example of using HTML in JLabel.

提交回复
热议问题