Skip to content
Advertisement

Text blocks in JOptionPane

The following code shows two labels with the same multiline html text. The labels differ, however, in the way their text is defined: one as a usual string, the other as a text block. The labels are displayed as expected, namely without any difference. The OptionPanes use the very same strings as the labels, but the text block is not rendered properly. Any idea why? (java version “16”)

JavaScript

Advertisement

Answer

The trailing carriage returns in txt2 make the text block unmanageable by your JOptionPane, instead explicitly consider the text block as a one-liner by using at the end of each line

JavaScript

This produces the following

enter image description here

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement