wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Setting size to fit text (JTextArea) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Setting size to fit text (JTextArea)" Watch "Setting size to fit text (JTextArea)" New topic
Author

Setting size to fit text (JTextArea)

Jean Hansen
Greenhorn

Joined: May 29, 2002
Posts: 2
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

Joined: Oct 18, 2000
Posts: 4121

"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


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting size to fit text (JTextArea)
 
Similar Threads
Set size for JOptionPane?
How to set the text in JTextarea from bottom.
Problems resizing using a split pane divider.
JTextArea
superscript text JTextArea