Article View: borland.public.jbuilder.java.swing
Article #1407Re: animate move of JSplitPane divider?
From: John McGrath [TeamB]
Date: Sat, 20 Dec 2003 00:28
Date: Sat, 20 Dec 2003 00:28
53 lines
2867 bytes
2867 bytes
On 12/19/2003 at 1:56:25 PM, Sam Seaborn wrote:
> I have a routine that automatically moves the divider of a JSplitPane
> from, say, 0 to 100 (to show/hide a panel in my frame). I simply use
> splitPane.setDividerLocation(i) and it works great.
>
> The thing is, I want to divider to slide back and forth with a smooth
> "animated" effect.
>
> I have tried something like the following:
[snip]
> But the result is, click the button, get a pause for a couple
> seconds, then the divider goes the final location. I don't see any
> animation.
That is what I would expect from the code you provided. What it does
is create 100 Runnable objects and post them to the AWT event queue
using SwingUtilities.invokeLater(), with a 1/10 second pause after
posting each event. After your button click action completes (which
takes about 10 seconds), the 100 Runnable objects will be executed
rapidly from the event queue, so the motion of the divider is not
apparent.
The javax.swing.Timer class is exactly what you need. It will run a
piece of your code periodically in the AWT event thread. The following
(untested) code should be more or less what you want:
public static final int LIMIT = 100;
public static final int INTERVAL = 100;
final Timer timer;
ActionListener timerAction = new ActionListener() {
public void actionPerformed( ActionEvent event ) {
int loc = splitPane.getDividerLocation();
if ( loc < LIMIT ) {
splitPane.setDividerLocation( loc + 1 );
} else {
timer.stop();
}
}
}
timer = new Timer( INTERVAL, timerAction );
timer.start();
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID:
<3fe3a5a8$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!petbe.visi.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3fe34916$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,c104217d747a468e X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2003-12-19 17:39:38 PST From: "John McGrath [TeamB]" <ng-b@JPMcGrath.net> Subject: Re: animate move of JSplitPane divider? Newsgroups: borland.public.jbuilder.java.swing References: <3fe34916$1@newsgroups.borland.com> User-Agent: XanaNews/1.15.7.4 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 NNTP-Posting-Host: 141.158.232.159 Message-ID: <3fe3a5a8$1@newsgroups.borland.com> Date: 19 Dec 2003 17:28:08 -0700 X-Trace: newsgroups.borland.com 1071883688 141.158.232.159 (19 Dec 2003 17:28:08 -0700) Lines: 53 X-Authenticated-User: jpmcgrath Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!petbe.visi.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail