🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Getting a table to scroll a new row into view

#9565
From: John P. McGrath
Date: Tue, 29 Feb 2000 00:00
33 lines
1753 bytes
On Mon, 28 Feb 2000 13:16:00 -0500, E Steel wrote:

> I have a JTable in a JScrollPane with a vertical scrollbar with
> autoScrolls set to true, with a subclassed DefaultTableModel that does
> not allow editing in column 1 of the table. What I want to do is when I
> add a row to the table I want it to scroll into view.
>     When I do:
>             MyTabelModel tableModel.addRow()
>                     No scrolling takes place
>             I added the following line of code after the addRow()
>                 JScrollPanel.getVerticalScrollBar().setValue
> (JScrollPanel.getVerticalScrollBar.getMaximum());
>             The table scrolls to just before the new row, but the new
> row does not scroll into view.

The problem is that you are asking the scroll bar for its maximum value 
before the JTable has notified it that the viewport's view (the JTable) 
has grown.

It may work if you delay the execution of the scrolling code until later.  
For example:

    SwingUtilities.invokeLater( new Runnable() {
        public void run() {
            JScrollPanel.getVerticalScrollBar().setValue
                (JScrollPanel.getVerticalScrollBar.getMaximum());
        }
    }

-- 
John P. McGrath
<JPMcGrath@fast.net>
<jpm@nscs.fast.net>
Technical Details
Message-ID: <MPG.13253752d4eaba139897cc@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <38BABB60.C129836@tis4000.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,9816815c546accd2
X-Google-Attributes: gid111d45,public
From: John P. McGrath <JPMcGrath@fast.net>
Subject: Re: Getting a table to scroll a new row into view
Date: 2000/02/29
Message-ID: <MPG.13253752d4eaba139897cc@forums.borland.com>
X-Deja-AN: 591201392
References: <38BABB60.C129836@tis4000.com>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.swing