This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting size to fit text (JTextArea)

 
Jean Hansen
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need to set the height of a JTextArea with fixed width to fit a text inside.
How can I do it ?
Actually what I�m trying do to is to make cells multiline in a JTable without specifing a fixed row height. It should be detected depending on columns widths and text length of each cell.
Thanks
Jean
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"jeanhansen" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it here.

You should be able to call setPreferredSize() in the getTableCellRendererComponent() method of your renderer... since you have a reference to the table, row, column and the value that is going to be displayed you should be able to calculate it. I think that if you call super.getPreferredSize() it will return the size needed for the text... not sure if it takes into account the set width, though...

Thanks! and welcome to the JavaRanch!

-Nate
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic