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

JTable doesn't repaint

137 views
Skip to first unread message

Henri Benoit

unread,
Mar 7, 2001, 9:39:48 AM3/7/01
to
Hi,

I have a JTable. At the beginning the model is empty. Then I feed data
in the model but nothing happens. I just wrote a few
System.out.println(<name of the function>) at the beginning of all the
functions. It says I set the data in the model (5 rows) and then
getRowCount is called 5 times and each time returns 5. But the display
isn't refreshed and getValueAt is never called. After setting the rows
in the model, I do call repaint() but it doesn't seem to do anything
(The five calls to getRowCount() are made after I call repaint()).
I got another table which works fine. I couldn't find any difference in
the code. The only difference I see is that the one which works is
contained in a JScrollPane in a JFrame and the one which doesn't work is
in a JScrollPane in a JPanel in a JTabbedPane.
Has anybody experienced the same problem and solved it ?

Thanx

--
Henri BENOIT

Siemens AG
Medical Solutions
HS IMS I
Henkestrasse 127
91052 ERLANGEN

phone : +49 (0) 9131 84 6135
fax : +49 (0) 9131 84 2792
email : henri....@shs-online.de

---

la lettre seule tue, mais l' ESPRIT des lettres vivifie

henri.benoit.vcf

Henri Benoit

unread,
Mar 7, 2001, 9:41:45 AM3/7/01
to
It does work but I have to select another tab in the tabbedpane and come
back.

Henri Benoit schrieb:

henri.benoit.vcf

Greg Jablonski

unread,
Mar 7, 2001, 10:00:34 AM3/7/01
to
It works because if you select another tab and come back jTable is
refreshing by itself. To see changes instantly you need to call revalidate()
method on JTable and then repaint() after setting the data.

Regards
Greg J.

Henri Benoit

unread,
Mar 8, 2001, 5:28:54 AM3/8/01
to
Thanx for the info !!!

Greg Jablonski schrieb:

henri.benoit.vcf

Steve Crook

unread,
Mar 9, 2001, 6:17:14 AM3/9/01
to
If your model is derived from AbstractTableModel you only need to make use
of the fire... methods it provides. When you've modified the model, call one
of them to get the table to redraw. They generate a TableModelEvent which is
sent to the table (it's a listener of the TableModel) and the tableChanged
method is called and this calculates just how much of the table needs to be
redrawn. If you just call invalidate() or repaint() you may end up drawing
much more of the table than you really need to, and this can slow things
significantly if your renderers are drawing something complex.

HTH

Steve

"Henri Benoit" <henri....@shs-online.de> wrote in message
news:3AA64834...@shs-online.de...

0 new messages