wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes customizing a JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "customizing a JTable " Watch "customizing a JTable " New topic
Author

customizing a JTable

Frank Hale
Ranch Hand

Joined: Mar 25, 2000
Posts: 230
I'm looking for code examples which customize JTables in different ways. Is there any sites which has some examples like this?
Thanks,
Frank
Frank Hale
Ranch Hand

Joined: Mar 25, 2000
Posts: 230
Well I did manage to find this site which has alot of useful JTable examples.
http://www2.gol.com/users/tame/swing/examples/SwingExamples.html
Have fun,
Frank
Frank Hale
Ranch Hand

Joined: Mar 25, 2000
Posts: 230
I'm still looking for an example which will demonstrates how to have rows that are automattically sized. Basically In my table I will have some cells which are multilined. I need all the text in this cell to be viewable, so each row quite possibly will have a different row height. How can this be done? Just think of the table which shows your new messages in Microsoft Outlook and you will understand what I am trying to achieve.
Thanks,
Frank
Michelle Baxter
Greenhorn

Joined: Jun 09, 2000
Posts: 2
Take a look at the examples that discuss setting the cell renderers. I did something similar by setting the cell renderer to a text area. Then you can iterate through the columns of that row asking the renderer for the size it would be and get the one with the largest height to set the rowHeight. For this to work you also have to set the column widths (another iteration of using some "reasonable" value or the column header width, whichever was larger) so the text area knows how to wrap. Sorry I don't have anything online to show you - I got all of this from the Java Swing forum and from a book: graphic Java 2 - Mastering the JFC by Geary (the Swing volume). Hope this makes sense enough to help!
Jay Shaw
Greenhorn

Joined: Jun 20, 2001
Posts: 6
Hello Michelle,
I also encountered the same kinda problem. I tried doing what you said, but some if i have a small text the row height for that row is very large. And if i have a long text in my text area cell renderer then i the text in that cell is not showing up as multiline but only shows a part of the text in a single line, though the height is set as previous cell. I am kinda confused if my logic is any different.
Could you send me some code snippets regarding this like the cell renderer code and the iteration code.
really appreciate it,
Thanks
Jay
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: customizing a JTable