File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Forcing JTable column widths when data is updated - where am I going wrong?
 
Similar Threads
Scrollable JTable
Loosing focus on entire column
JTable - JDBC - Vectors
problem resizing JTable column
Customizing JTable