Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JTable.setModel() has problem?

0 views
Skip to first unread message

Jun Wu

unread,
Sep 7, 2001, 5:24:03 PM9/7/01
to
Hi,
I recently had this problem:

in a JTable object, one thing I have to do is to replace its current
TableModel with a new TableModel, the code will look like this:

...
table.setModel(newTableModel);
...

But, if the newTableModel is smaller or bigger than the previous one (in
terms of ColumnCount()), some time I will get some exception like this:

Exception occurred during event dispatching:
java.lang.ArrayIndexOutOfBoundsException: 2 >= 2
at java.util.Vector.elementAt(Unknown Source)
at javax.swing.table.DefaultTableColumnModel.getColumn(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintWithBuffer(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown
Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

I checked in the overrided getCellRenderer method, it sometime the
tableModel's columnCount is different than table's columnCount. It looks
like the JTable is rendering the table column by column during the setModel.
Then at some point, the table's TableModel has finished changing, but the
renderer is still indexing the previous cells. For example, the previous
table is 12 by 8, the new one is 3x4, when the model is rendering the 7th
column, it might have this exception.

Has anyone got this problem before? Anyone know how to dal with this?

Thanks!

-jw


Fred Sells

unread,
Sep 7, 2001, 6:10:02 PM9/7/01
to
I would like to specify the background color of a JToggleButton when it is
selected.

I've tried doing the setBackground() method on the ItemChangeListener, but it
appears that the button is subsequently setting the background to it's default
dark gray.

It appears that I can do this on a JRadioButton, but I cannot figure out how to
get rid of the little circle icon.

Has anyone solved this?

Gregory A. Swarthout

unread,
Sep 7, 2001, 6:36:13 PM9/7/01
to
Try calling the following method on table after changing its model:

createDefaultColumnsFromModel();

Babu Kalakrishnan

unread,
Sep 8, 2001, 7:39:53 AM9/8/01
to

Are you calling setModel(newTableModel) from a thread that is different
from the event despatch thread by any chance ?

In which case wrap the call into a SwingUtilities.invokeLater() and
force the model update to take place in the EDT.

BK

Jun Wu

unread,
Sep 8, 2001, 12:03:08 PM9/8/01
to
Thanks a lot! This leads me to the right track and fixed the problem.

-Jun

"Babu Kalakrishnan" <ka...@sankya.com> wrote in message
news:slrn9pk0s...@ganga.sankya.com...

0 new messages