Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

JTable.setModel() has problem?

已查看 0 次
跳至第一个未读帖子

Jun Wu

未读,
2001年9月7日 17:24:032001/9/7
收件人
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

未读,
2001年9月7日 18:10:022001/9/7
收件人
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

未读,
2001年9月7日 18:36:132001/9/7
收件人
Try calling the following method on table after changing its model:

createDefaultColumnsFromModel();

Babu Kalakrishnan

未读,
2001年9月8日 07:39:532001/9/8
收件人

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

未读,
2001年9月8日 12:03:082001/9/8
收件人
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 个新帖子