• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TextArea

 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out my answers
A TextArea is made in a proportional font like this:
TextArea ta = new TextArea ("hello", 5, 5);
Which are true?
a) It will show exactly 5 rows.
b) It will show exactly 5 columns.
c) Each item can only be 5 letters long.
d) You can edit the contents.
e) You can have multiple fonts inside it.
a,b,c
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the answers should be a) b) d)
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it's just A and D. In a proportional font, the widths of the characters vary, and you can fit a lot more "1"'s in a given space than you can "W"'s. The width of the TextArea will be 5 "average" characters, but you may see more or less at one time, and if you keep typing on a line the TextArea will scroll horizontally to allow you to keep typing. So B and C are both wrong.
I can't find a spec that says the TextField will be editable by default, but it seems to be true for jdk 1.3 beta at least.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In RHE p328 TextArea(String text, int nRows, int nCols) constructs a textarea whose initial content is text, with the specified number of rows and columns. So a & b are true. When you want it uneditable you have to call the setEditable(false) method so, it look like it defaults to editable, so d is true. C is definitely false. And given the examples given in RHE I would assume that only one font at a time, but I haven't tested that. Provisionally e false.
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, B is definitely false because it contains the word "exactly". Note that RHE p.329 addresses the issue of proportional fonts, and states that the column width is taken as an average of all the characters' widths. So if characters have above-average width, not so many will fit in the field, while for below-average width you can fit more in. I have tried this with an actual TextArea to verify it - "5 character widths" was enough for almost 3 "W"'s, or about ten "1"'s, using my default font.
As for multiple fonts - what method could you use to have different fonts? I don't think there's anything to test, unless someone can suggest a method to try. TextArea has only one setFont() method, and it sets the font for the whole area.
 
Hugh Smith
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that there is a miscommunication between characters and columns. The API says:
TextArea
public TextArea(String text,
int rows,
int columns)
Constructs a new text area with the specified text, and with the specified number of rows and columns. This text area is created with both vertical and horizontal scroll bars.
Parameters:
text - the text to be displayed.
rows - the number of rows.
columns - the number of columns.
------------------------------------------------------------
So, the matter of how many characters will fit into a column is a different question than how many columns, I think.
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But the idea of "columns" makes no sense if you're using proportional fonts - the characters don't line up into columns.
This is in a proportional font:
12345678901234567890123456
abcdefghijklmnopqrstuvwxyz
WWWlllllllllllllllllWWWWWW
lllllllWWWWWWWWWWWWlllllll
12345678901234567890123456
And this is in a constant-width font:
<code>12345678901234567890123456
abcdefghijklmnopqrstuvwxyz
WWWlllllllllllllllllWWWWWW
lllllllWWWWWWWWWWWWlllllll
12345678901234567890123456</code>
See the difference? How wide should a TextArea be to enclose 5 "columns" in the first case?
Since the API says nothing at all about what "columns" means when using a proportional font, ignore it. Since RHE do address the issue, listen to them. And since you should have access to a working jdk, try this:


[This message has been edited by Jim Yingst (edited February 10, 2000).]
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think ONLY d is Correct.
The TextArea constructed with TextArea("Somestring", 5,5) will not EXACTLY display 5 rows, so A is also false
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Heh. I didn't even notice that - you're right. At least using JDK 1.3 on Win 98. It sure looks like there's space for 5 rows, but when you put the fifth one in it does a little auto-scroll for no good reason, and you only see 4 lines plus a blank area that's probably big enough fo 95% of a line. How annoying.
I'm inclined to call this a bug, however. The TextArea certainly should be able to display 5 rows fully, since even with proportional fonts the characters are always in discrete rows, though not in discrete columns. I.e. while it's fundamentally impossible for B to be true, A is only false because someone screwed up. I've noticed similar minor sizing bugs elsewhere in AWT and Swing - e.g. scrollbars that don't appear quite as readily as they need to when you resize a ScrollPane. You can sometimes get up to half a line out of view without the scrollbar appearing. Very annoying.
As a last note, if you replace TextArea with a JTextArea, it works fine, displaying exactly 5 rows (at least on my platform).
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic