문제

I'm getting some inconsistent HTML display in a Swing message dialog. The first example call below is fine, but the second one displays one of the break tags as literal text. What's going on here?

import javax.swing.*;

class Test {
    public static void main(String... args) {
        SwingUtilities.invokeLater(() -> {
            JOptionPane.showMessageDialog(null,
                "<html>line 1<br>line 2<br>line 3");
            JOptionPane.showMessageDialog(null,
                "<html>line 1<br>\nline 2<br>\nline 3");
        });
    }
}
도움이 되었습니까?

해결책

Don't know what the problem is but it looks like a JLabel renders the HTML correctly:

JLabel label = new JLabel("<html>line 1<br>\nline 2<br>\nline 3");
JOptionPane.showMessageDialog(null, label);

Which doesn't really make sense because I thought a JOptionPane would us a JLabel to render the text?

다른 팁

So do something like this

JOptionPane.showMessageDialog(null,
"<html>line 1<br>line 2<br>line 3");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top