File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JtextArea with scroll

 
Craig Parsons
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Craig Parsons
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can be notified of changes to the content of a JTextArea by writing a DocumentListener
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic