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.
Joined: Sep 08, 2004
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?
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.
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
Joined: Sep 08, 2004
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 JOptionPaneJTextArea 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?
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.