• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JtextArea with scroll

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can be notified of changes to the content of a JTextArea by writing a DocumentListener
 
It is difficult to free fools from the chains they revere - Voltaire. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic