0

How to display arraylist of obejects each in separate line? I have this code currently it display only in one line. I want to use the "\n" but how to add it in JOptionPane?

   ArrayList<String> ordered = new ArrayList<String>();
            case "Sales Report File":
                JOptionPane.showMessageDialog(null,"Items list sold: " + 
                            ordered(this outputs in one line)
                            ,"Sales Report ~ ",JOptionPane.PLAIN_MESSAGE);       
Xen
  • 105
  • 9
  • When using a JOptionPane, the only way to control line breaks is by generating HTML. – GhostCat Oct 20 '20 at 06:33
  • It didnt answer my question.. I want to display the array list of object in new line. Like example Array list objects have "Candy, Gums, Cookies, Chips" I want Candy in new line and Gums in new line, for every objects.. – Xen Oct 20 '20 at 06:48
  • It does. You need to create a HTML string that contains the data you want to display, together with HTML line breaks. You cant use "\n" because JOptionPane doesnt care about that. So you have to iterate your list, and put together a valid HTML string. – GhostCat Oct 20 '20 at 06:50
  • Do you know to code it? I'm having problems on it on how.. – Xen Oct 20 '20 at 07:06
  • Please understand that we help you solving problems, we dont solve them FOR you. Learning programming is about trying things yourself. As said: you have to iterate your list ... and you have to build a string that contains valid HTML. You can use a search engine, and you will find plenty of examples for both these things. Remember, it is your homework, your classes, your education. Try writing code yourself. If you then run into a specific problem, that you cant solve for hours, and even after talking to your peers, then you are welcome to write a new question here. – GhostCat Oct 20 '20 at 07:16

0 Answers0