• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to effectively print table using for loop with JOptionPane.showMessageDialog  RSS feed

 
David Barry
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what I'm missing here. I am trying to format my output using JOptionPane using a single window and I can't figure out what I'm doing wrong. Fairly certain the problem has to do with me trying to create a new table each time I run through the for loop. This is not what I'm trying to do, but I'm not sure what else to do. Any insight into what I could do to improve would be greatly appreciated!

Thanks,
John

 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't figure out what I'm doing wrong.

Please explain what the program is doing that you think is wrong
and explain what you want it to do differently.
 
David Barry
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So when the program runs, I want it to display one JOptionPane that has a  table of the "header" row plus the 7 rows of data. As it runs now, it only displays the "header" row and nothing else.
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To display all the data the user enters on one panel, save the lines in a String and display that String after all the user's input has been gathered.
Use the "\n" character in the String where you want the following part of the String on the next line.

Add a print statement to print the value in rows that has been built so you can see what the program has done.
 
David Barry
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like this?

 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like this? 

Does it do what you want?
 
David Barry
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. I want it to format the data in a table format. Which is what I'm trying to do with the line I have commented out, but it's not working.
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you write an html page as a model that formats the way you want?
Then using that as a goal for the code,
write java code that will generate a String with the html that you have written as a model.

If you print the contents of rows as you work on the code you'll see where the code needs to be changed to get the manually written html page.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!