JScrollPane not refresing

Ok, you all helped me get my JTable to show up correctly and I thank you for that! Now I am having trouble getting it to scroll correctly. When the JScrollPane scrolls off of the initial viewport it will not refresht the column headers however it will refresh the data within those columns. Any idea why? Here is code snipit. *Note: this is not my real code but this code behaves the same ways as my real code. Real code has nonstandard classes, so I post this code with standard classes to try to get some help.*

DefaultTableModel model =new DefaultTableModel();

JTable table =new JTable(model);

table.setModel(model);

JScrollPane scp =new JScrollPane(table);

//set preferred seizs

table.setPreferredSize(new Dimension(600, 200));

scp.setPreferredSize(new Dimension(400, 200));

table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

table.setModel(model);

//set table data and headers

Object[] temp =new Object[]{"Rate ","Rule","Rounding ","Decimal "};

model.setColumnIdentifiers(temp);

model.fireTableStructureChanged();

Object[] temp1 =new Object[]{"1","2","3","4"};

model.addRow(temp1);

model.fireTableRowsInserted(0, model.getRowCount());

[1853 byte] By [doopsterus] at [2007-9-30 20:24:34]
# 1
*TITLE* sorry should be *Refreshing...
doopsterus at 2007-7-7 1:09:10 > top of Java-index,Java Essentials,Java Programming...
# 2

i have several tables nearly identical to yours and where my code differs from yours is in the following places

> table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

(i want my table to automatically resize so i dont mess with this)

AND

> model.fireTableStructureChanged();

(the way I handle events is just delete all the rows myself, and add the new rows)

AND

> model.fireTableRowsInserted(0, model.getRowCount());

(the way I handle events is just delete all the rows myself, and add the new rows)

>

> [/code]

I think the problem probably lies in your fireing to the listeners.

moerderin at 2007-7-7 1:09:10 > top of Java-index,Java Essentials,Java Programming...
# 3
why does that JTable.AUTO_RESIZE_OFF cause it not to refresh? So I how can I get the HorzontalScroll bar to be shown all the time w/o doing JTable.AUTO_RESIZE_OFF?
doopsterus at 2007-7-7 1:09:10 > top of Java-index,Java Essentials,Java Programming...
# 4

> why does that JTable.AUTO_RESIZE_OFF cause it not to

> refresh? So I how can I get the HorzontalScroll bar

> to be shown all the time w/o doing

> JTable.AUTO_RESIZE_OFF?

i just added that line of text to my table to test it, and it still worked fine. as i said before, i think it has something to do with your:

table.fireblahblahbalh (the two fire lines you have where you tell the action listeners SOMETHING happend)

moerderin at 2007-7-7 1:09:10 > top of Java-index,Java Essentials,Java Programming...
# 5
oops, model.blahblahblah, not table. these two lines:> > model.fireTableStructureChanged();> > model.fireTableRowsInserted(0, model.getRowCount());
moerderin at 2007-7-7 1:09:10 > top of Java-index,Java Essentials,Java Programming...
# 6
i just add all your code to my table, and it continued working perfectly fine. maybe your problem lies somewhere else?
moerderin at 2007-7-7 1:09:10 > top of Java-index,Java Essentials,Java Programming...
# 7
Don't [url http://forum.java.sun.com/thread.jsp?forum=57&thread=564685]crosspost[/url]. This is a Swing related question and should only be posted in the Swing forum.
camickr at 2007-7-7 1:09:10 > top of Java-index,Java Essentials,Java Programming...
# 8
read.... question is worded a bit differently however it is the same principal, you are right. Sorry. Just can't figure this out!
doopsterus at 2007-7-7 1:09:10 > top of Java-index,Java Essentials,Java Programming...
# 9

Ok here is the problem. For some reason when you set a preferredsize on the table it does not like that and will not allow you to resize the columnIdentifiers. So don't specify a prefered size for the actual table but insteas set the size of the columns to make the table the size you want. Thanks for all of the swell help!

Doopsterus

oh this is a cross post reply ... :) http://forum.java.sun.com/thread.jsp?forum=57&thread=564685 Just wanted to make sure eveyone knew this issure was closed. Thanks!!!

doopsterus at 2007-7-7 1:09:10 > top of Java-index,Java Essentials,Java Programming...