🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #7512

Re: JTable scrolling related question

#7512
From: Torsten Welches
Date: Mon, 15 Jan 2001 20:56
30 lines
2103 bytes
Hartmut,

I can reproduce your problem now. I guess John was right,
scrollRectToVisible fails because the necessary repaint happens after the
fact.

So invokeLater will do it, although I still consider it a hack.

    int count = 400;
    String[][] data = new String[count][3];
    for (int i = 0; i < count ; i++) {
      data[i][0] = "A_" + i;
      data[i][1] = "B_" + i;
      data[i][2] = "C_" + i;
    }
    String[] columns = {"Field_A", "Field_B", "Field_C"};
    table.setModel(new javax.swing.table.DefaultTableModel(data, columns));
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        scroller.getViewport().scrollRectToVisible(
table.getCellRect(table.getRowCount(), 0, true ) );
      }
    });

Please note that your removeRow/addRow approach is pretty inefficient, it's
much faster to set up the whole model "outside the table" and then to hand
it to the table in one shot. You don't even have to remove the old rows this
way.

Torsten
Technical Details
Message-ID: <3a63648b_1@dnews>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!cyclone-sf.pbi.net!63.208.208.143!feed2.onemain.com!feed1.onemain.com!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!wn4feed!worldnet.att.net!164.128.36.58!newsfeed-zh.ip-plus.net!news.ip-plus.net!bornews.borland.com!dnews!194.8.196.179
References: <3A1583E1.8FD78A76@netrisk.com> <3a15c300_2@dnews> <3a5c6686_2@dnews> <MPG.14c70100271fd34c989e6f@forums.borland.com> <3a62fa9f_1@dnews> <3a630ad3$1_2@dnews> <3a632376_1@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,1fc5e943f0feb2d4
X-Google-Attributes: gid111d45,public
X-Google-ArrivalTime: 2001-01-15 13:02:24 PST
From: "Torsten Welches" <torsten.welches@who.cares.netcologne.de>
Newsgroups: borland.public.jbuilder.java.swing
References: <3A1583E1.8FD78A76@netrisk.com> <3a15c300_2@dnews> <3a5c6686_2@dnews> <MPG.14c70100271fd34c989e6f@forums.borland.com>  <3a62fa9f_1@dnews>  <3a630ad3$1_2@dnews> <3a632376_1@dnews>
Subject: Re: JTable scrolling related question
Date: Mon, 15 Jan 2001 21:56:00 +0100
Lines: 32
X-Newsreader: Microsoft Outlook Express 4.72.3110.5
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
NNTP-Posting-Host: 194.8.196.179
Message-ID: <3a63648b_1@dnews>
X-Trace: 15 Jan 2001 12:58:51 -0800, 194.8.196.179
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!cyclone-sf.pbi.net!63.208.208.143!feed2.onemain.com!feed1.onemain.com!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!wn4feed!worldnet.att.net!164.128.36.58!newsfeed-zh.ip-plus.net!news.ip-plus.net!bornews.borland.com!dnews!194.8.196.179