• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextaArea - Lock the size, can it be done?  RSS feed

 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey everyone,

I have been looking at the API and google, but I cannot find the answer to my question.

with a JTextArea can it be locked so that it only contains 2 rows and no more?
if so how can I do this?

davy
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in this you would need to control the size of the textArea
e.g. frame.setResizable(false);

compile/run, start typing and it will be limited to 2 lines.
if you then narrow the frame, the typed text will go to 3 or more lines

 
Ryan Giomi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Davy,

If I understand you correctly, then here is how I do it:

(Code below... didnt bother with the code script as this is a subsection)
#######################################################################
import java.awt.Dimension; //need this for dimension

Dimension d = new Dimension(10,24);

JTextArea t3WorkoutTextArea = new JTextArea(10,24);

t3WorkoutJP.add(t3WorkoutTextArea);//add the text area to your jpanel
t3WorkoutTextArea.setPreferredSize(d); //ThIS WHAT YOU WERE ASKING ABOUT. It
//locks your columns and rows.

#######################################################################
Hope that helps.
[ May 01, 2007: Message edited by: Ryan Giomi ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!