File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes JTable Columns width Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "JTable Columns width" Watch "JTable Columns width" New topic
Author

JTable Columns width

Tahir Abbas
Ranch Hand

Joined: May 05, 2007
Posts: 45
Hi to everyone,

I want to make the width of columns in JTable according to the width of biggest cell. But for this I think I need to read almost all the record set. It will definately slow down the processing speed so its not looking me a good solution.

Another solution that I am thinking is to extend the length of heading titles (array of field names) by filling it with space, accroding to database schema and then adjust the the column width according to these headers. But in some cases column width may be unnecessarialy wide.

I would like to know your opinion to get a better solution.

Thanks! in Advance
Best Regards!
Tahir
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5529
    
  13

Hi Tahir,

My advice: don't make your life harder if it's not needed, so just don't do it. All my columns are distributed evenly in the available space and the CSR (user) can resize them if he wants.

Maybe another possibility is to use percentages to make certain columns a bit bigger than others. It can be easily done and won't slow down the processing. For some example code, click here.

Hope it was helpful.
Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Tahir Abbas
Ranch Hand

Joined: May 05, 2007
Posts: 45
Thanks! Roel

Its very easy to just display data in JTAble, no need to go beyond the requirements and ofcourse if I'll use Swing in future then I'll use IDE.

This time my JTable shows Field Names and an extra column Serial Number. All columns have equal width, as default. Table displays all screen wide. I didn't apply any TableModel or any other option. Do you think its enough because it fulfills the requirement "Result must be in JTable".

Or What formatting do you think I should apply. There are 100 Marks for General Consideration.

Best Regards!
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5529
    
  13

Hi Tahir,

My JTable was pretty straightforward: columns distributed evenly, used custom table model, single selection, auto resize of all columns and that's it. I think decisions concerning the JTable don't affect the general considerations score section, rather the gui one.

Kind regards,
Roel

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable Columns width