Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to give scrollbars to JTextArea when lines are greater than 3??

 
umesh kacha
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have added one JTextArea inside JScrollPane which is finally inside JPanel

Now based on text/lines inside JTextArea I want that scrollbars must come only if lines are greater than 3

if lines are less than 3 then it should not show scroll bars

Please help

I tried textArea.getLineCount() method but in every case it is returning only 1 as output even if lines are more than 1

In short my problem is that I want to know number of lines a textarea by using which I will set preffered size to JPanel on which I am putting JTextArea

Please help

 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTextArea has a constructor where you can define the row and column count.
What have you set for setLineWrap and setWrapStyleWord? These booleans will affect the getLineCount
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic