JTextArea
I've read the tutorial on TextAreas but i still don't understand how this works
text1 =new JTextArea (10, 2);
I don't really understand the 2 numbers at the end. My teacher wasn't 100% sure about it either. Which one sets the number columns? and which one sets the number of rows? Does it limit the number of letters?
thanks in advance
[398 byte] By [
ELIJAHa] at [2007-11-27 4:54:49]

# 1
> I've read the tutorial on TextAreas but i still don't
> understand how this works
> text1 = new JTextArea (10, 2);
> I don't really understand the 2 numbers at the end.
> My teacher wasn't 100% sure about it either. Which
> one sets the number columns? and which one sets the
> number of rows?
You should tell your teacher about the API documentation:
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JTextArea.html
You can't program in Java withuot it, and you shouldn't be allowed to teach Java if you don't know about it. Here you will find, among other things, documentation for all the JTextArea constructors, including what the input arguments are for.
> Does it limit the number of letters?
> thanks in advance
You'll find information about this as well in the link above. Good luck!
# 2
> I've read the tutorial on TextAreas but i still don't
> understand how this works
> text1 = new JTextArea (10, 2);
> I don't really understand the 2 numbers at the end.
> My teacher wasn't 100% sure about it either. Which
> one sets the number columns? and which one sets the
> number of rows? Does it limit the number of letters?
> thanks in advance
Shoot, look at the api, but also try out different numbers and see what happens.
# 3
In all fairness, the API description isn't the clearest on what it does.
The row and column values are just used to give the text area a preferred size based on the current font. It does not control the total number of rows allowed in the text area not does it control the number of character that can be added for each row.
text1 = new JTextArea (10, 2);
So you will be able to see 10 rows of text at one time before the scrollbar appears (assuming you add the text area to a scrollpane.
Well, the 2 is not very realistic, but if you use a monospaced font then you will be able see 2 characters on each row. If you use a non-monospaced font then you will see more "iii" then "WWW" on the same row
As mentioned above the meaning of the row parameter should be clear if you took the time to play around a lilttle bit. The column parameter is slightly more involved.
# 4
> In all fairness, the API description isn't the
> clearest on what it does.
>
In the original post the OP asks:
"Which one sets the number columns? and which one sets the number of rows?"
This is very clearly answered in the API, and if you don't know where to find this information you're not fit to be a Java teacher (IMO).
Now, as for the effect of these two parameters, the API says about the same thing as what you just did, and I agree that might not be all that clear for a Java beginner. Experimenting with it is an excellent way of learning.
# 5
>> "Which one sets the number columns? and which one sets the number of rows?"
> This is very clearly answered in the API,
Agreed, which is why I didn't attempt to answer that.
> Now, as for the effect of these two parameters, the API says about the same thing as what you just did
Disagree, which is why I took the time to explain how the parameters are used. Nowhere in the API does the description mention the words "preferred size". Nowhere does it mention that the number of characters displayed per row is different depending on the type of font used or the characters displayed in the row.
Many people think these parameters are used to control the number of characters per line and the maximum number of lines that can be added to the text area. Now its obvious if you experiment by typing in text that this in not the case which is why I also encouraged the OP to experiment.
# 6
>
> Disagree, which is why I took the time to explain how
> the parameters are used. Nowhere in the API does the
> description mention the words "preferred size".
Actually, it does. Copied and pasted from http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JTextArea.html:
"java.awt.TextArea has two properties rows and columns that are used to determine the preferred size. JTextArea uses these properties to indicate the preferred size of the viewport when placed inside a JScrollPane to match the functionality provided by java.awt.TextArea. JTextArea has a preferred size of what is needed to display all of the text, so that it functions properly inside of a JScrollPane. If the value for rows or columns is equal to zero, the preferred size along that axis is used for the viewport preferred size along the same axis."
# 7
> Actually, it does. So it does, I was just reading the constructor description which simply says:Constructs a new empty TextArea with the specified number of rows and columns.