• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Setting size to fit text (JTextArea)

 
Greenhorn
Posts: 2
  • 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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!