• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Locking the JText Area

 
Mabel Ahmad
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


How can I lock the j text area so that the user cannot edit the text?
Also how can I make "Archers" in bold?


Thank you very much for your help!
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> How can I lock the j text area so that the user cannot edit the text?
ta.setEditable(false);
(where ta = your textArea)

> Also how can I make "Archers" in bold?
ta.setFont(ta.getFont().deriveFont(Font.BOLD));
note: this will change the font for all the text in the textArea
 
Mabel Ahmad
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for your help.

I have another question. Would it be possible to set the size of a JTextArea? Like a set size of number of characters

For example if it was set to size 5 then it would looks like the the following examples [_____] <-- that is the JTextArea

[1____]
[23___]
[422__]
[42444]
[ February 18, 2006: Message edited by: Mabel Ahmad ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can:
set line wrap
change the font to monospaced
use FontMetrics to set the preferredSize

something like this



this will give you 3 rows.
I don't know whether you want a scrollpane, if so, it will cause problems
when the vertical scrollbar kicks in.
if you want to restrict it to e.g. 3 rows, you can add set the 'document' so
that it only accepts 15 characters (5 * 3 rows)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic