File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JTextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextArea" Watch "JTextArea" New topic


Holly Leery
Ranch Hand

Joined: Sep 08, 2004
Posts: 97
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

Joined: Sep 08, 2004
Posts: 97
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

Joined: Jul 08, 2003
Posts: 24199

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.

[Jess in Action][AskingGoodQuestions]
Rikki Bostelmann

Joined: Sep 25, 2004
Posts: 8
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,
Holly Leery
Ranch Hand

Joined: Sep 08, 2004
Posts: 97
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

Joined: Sep 24, 2004
Posts: 101
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

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Swing / AWT / SWT / JFace forum...

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: JTextArea
It's not a secret anymore!