• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextArea

 
Holly Leery
Ranch Hand
Posts: 97
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone explain to me how I use JTextArea with columns and rows. In the application I am doing right now I need three columns for sure and the rows would have to be x for now, because I prompting the user for a certain amount of information which depending how much information they enter changes the row amount. So can some one give me an example or ideas? If I did not give enough infomation then just let me know. Thank you in advance.
 
Holly Leery
Ranch Hand
Posts: 97
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anybody know anything about this? For information, I am wrting an application that prompts a user repeadedly until the user enters -999. After that I then use some if else statements to determine some more information. So in the end I will use JOPtionPane and JTextArea to show three columns of information and an unlimited number of rows depending on the information entered by the user. Any ideas?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Holly,

If you need to show data in columns, you should consider using a JTable, which is a spreadsheet-like thing. That's certainly what I would do.

If you have to use JTextArea -- because a school assignment says so, for example -- then your main alternative is just to use TAB ("\t", or ASCII 9) characters to separate the columns -- although unless every datum is the same size, even that's no guarantee everything will line up.
 
Rikki Bostelmann
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Holly,

or you might use a panel holding three different JTextAreas, although
then you might lose the control that the rows match up nicely(?).
Probably the best way is using JTable, as Ernest suggested.

Good luck,
Rikki
 
Holly Leery
Ranch Hand
Posts: 97
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah my assignment tells me to use JOptionPane and JTextArea. I still dont quite understand how I write the code though if I have a dialog box that pops up several times asking a user to input a number, well it pops up until the user tells it to stop by entering -999. How do I know what code to put into the JOptionPane JTextArea box? It's not like I can put x in because its random, there isnt a set number of times a user will enter in information. So I have a random amount of numbers that need to be put into the dialog box at the end. How does that work?
 
Chris Staten
Ranch Hand
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if this will help, but I'll give it a shot anyway.

What if you use an array that stores all of the users inputs and then create the output display with that information. That way you know how many rows you will need to output when the time comes to display the users inputs.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Swing / AWT / SWT / JFace forum...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic