File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: width proportion in DefaultTableModel 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 "NX: width proportion in DefaultTableModel" Watch "NX: width proportion in DefaultTableModel" New topic

NX: width proportion in DefaultTableModel

Davidd Smith
Ranch Hand

Joined: Jul 28, 2003
Posts: 62
Hi, everyone,
I use DefaultTableModel as the TableModel of JTable. I
rearrange the TableColumn's display width according to the
field's length, but after I use the DefaultTableModel's
setDataVector() method, all the columns become equal average
width. How could I keep the column's width proportion with DefaultTableModel?
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11778

Hi Davidd
Sorry, I am not answering your question, but just something for you to think about: I didn't bother setting the column sizes, and I was not penalized for it.
Regards, Andrew

The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Column widths are controlled by the TableColumnModel, not the TableModel. It's probably more trouble than it's worth to deal with this, IMO, as the relationship between the TableModel and TableColumnModel APIs is needlessly convoluted. E.g. you can set column titles in either one. It's easy to do something with the TableModel that screws up the titles you set with TableColumnModel, or vice versa. Since nothing in TableColumnModel is really required for the assignment, you'll probably live longer if you don't use it.

"I'm not back." - Bill Harding, Twister
Davidd Smith
Ranch Hand

Joined: Jul 28, 2003
Posts: 62
Hi, Andrew and Jim,
Thank you for your reply, I will follow you advice, it saves me a lot of time.
I agree. Here's the link:
subject: NX: width proportion in DefaultTableModel
It's not a secret anymore!