I was writing an applet before and was displaying information in a JOptionPane. Useing \n, I was able to make the information display multilined like this:


I unfortunately had to change my code from an applet to a JFrame and subsiquently my Labels to JLabels. Most of my code remains the same. However, ow when I display the information in the JOptionPane, it appears like this:

Name1 Grade1 Name2 Grade2 etc.

How do I make a multiline JLabel to print out in a JOptionPane?

Thanks but I am not dealing with HTML. I think I thought of a solution. I will use a textArea but make it un-editable.

Thanks but I am not dealing with HTML.

You may have missed the point here - JLabels automatically support most basic HTML items, so you use <BR> instead of \n in a JLabel

I don't think it will work because of the way I am doing it. I am reading from a text file into an arraylist and then adding it to a JLabel. My code looks like this:

            while (index<stop)

The \n does not do anything. I am not familiar with html at all so would I make the line look like this?


I still think I will try the text area thing I said before.

Wait, I found a solution. Even though I am making a JFrame as opposed to an applet, I use a Label instead of a JLabel. I tested this and it prints out the way I want it to.

This question has already been answered. Start a new discussion instead.