This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Forcing JTable column widths when data is updated - where am I going wrong? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Forcing JTable column widths when data is updated - where am I going wrong?" Watch "Forcing JTable column widths when data is updated - where am I going wrong?" New topic
Author

Forcing JTable column widths when data is updated - where am I going wrong?

Rachel Swailes
Ranch Hand

Joined: May 18, 2004
Posts: 434
Hi there

I have a JTable whose column width's I am setting before the table is visible. When the table is shown, the column are correctly sized.

When I load data into the table, the column width's change.

How do I get the column's width's to hold when the data changes? Amazingly, this is the only of the four tables on the screen that is doing this and I cannot pinpoint where the error is!

Many most kind regards,
Rachel


This is the code for setting up the table (the total's table)


This is the code that calculates the data in the table


This is the place where the new row data is put into the table model that governs the total's table
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
Can't see anything obvious although I suspect it's the fireTableChanged(null). To debug, write a method something like this (pseudo-code).

void dumpColumnState {
for each column in column table [
print "index = " + colIndex + " width = " + width;
}
}

Sprinkle liberally around your code and find which statement is clearing your column widths.
hth, D.
Rachel Swailes
Ranch Hand

Joined: May 18, 2004
Posts: 434
Hi Don

I found that it was during the setting of the Object[][] rowData to the new data that was coming in. Don't know why but at least it works now!

Thanks again!
Rachel
 
Consider Paul's rocket mass heater.
 
subject: Forcing JTable column widths when data is updated - where am I going wrong?