This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Locking the JText Area Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Locking the JText Area" Watch "Locking the JText Area" New topic
Author

Locking the JText Area

Mabel Ahmad
Greenhorn

Joined: Feb 03, 2006
Posts: 8


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

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Feb 03, 2006
Posts: 8
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

Joined: Jun 09, 2003
Posts: 4632
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)
 
 
subject: Locking the JText Area
 
Similar Threads
font size and JDialog box
JTextaArea - Lock the size, can it be done?
Finding current line number - textarea
JScrollPane not working
Populate the 'current' JTextField via a button/label