aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JtextArea with scroll Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JtextArea with scroll" Watch "JtextArea with scroll" New topic
Author

JtextArea with scroll

Craig Parsons
Ranch Hand

Joined: Jan 28, 2004
Posts: 40
I have a JTextArea define with 1 row. I have also set its setLineWrap to True. As the user enters data into field I want the textfield to expand from 1 row upto 3 rows as needed, so that I can see all 3 rows at once, which it does. But if the user enters more data and more than 3 rows are needed I want to add scroll bars using JSrollPane.
I believe this logic is similiar to most " To: " email address boxes in have seen.
Any ideas?
Thanks,
Craig
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Well, one way to do it is that when you get more than 3 items, remove the Textarea from the Panel (whatever that may be), add the TextArea to a JSCrollPane, then add the JScrollPane to the panel where the Textarea was.


GenRocket - Experts at Building Test Data
Craig Parsons
Ranch Hand

Joined: Jan 28, 2004
Posts: 40
Is there a way to count or keep track of the number of rows that are added to the JTextArea? This way I would know when I need to add the scroll bars.
Craig
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Craig Parsons:
Is there a way to count or keep track of the number of rows that are added to the JTextArea? This way I would know when I need to add the scroll bars.
Craig

Seems to me like you might want to look into using a JList
Craig Parsons
Ranch Hand

Joined: Jan 28, 2004
Posts: 40
I thought about a JList and it will not work for what I need.
If I use getRows() I can get the number of rows in my textArea but I'm not sure where in my program i need to check that. In other words when I have a textarea and my words wrap, a new row is added to the textarea. Where or what part of a program controls that? Do I need some sort of listener for that?
Craig
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
You can be notified of changes to the content of a JTextArea by writing a DocumentListener


SCJP2. Please Indent your code using UBB Code
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JtextArea with scroll