Skip to main content

[JAVA2D] animating Swing components

6 replies [Last post]
Anonymous

Hi.

This is (mostly) off-topic, but maybe someone can point me to the
proper place to ask this.

I am comfortable creating animations in general by using Java 2D
drawing and background threads.

I'm not sure how to apply some of these concepts when using Swing
components, however.

One thing I'd like to animate is a JSplitPane, so when a user clicks
a button or chooses a menu item, the JSplitPane will be adjust to
some certain size, but I don't want to just "jump" to the new size. I
want to see the JSplitPane scroll in real-time to its final size.

There are other such animations I'd like to do, like scrolling a
JTable or JTree to some specific position, while showing all the
intermediate scroll positions to the user.

Any pointers?

Thanks,

Rob Ross, Senior Software Engineer
E! Networks
rross@eentertainment.com
---------------------------------------------------
"Beware of he who would deny you access to information, for in his
heart he dreams himself your master." -- Commissioner Pravin Lal

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Ted Hill

Instead of using invokeAndWait from a background thread, I think using a
Swing Timer would be a better choice.

See:

http://java.sun.com/docs/books/tutorial/uiswing/misc/timer.html

-----Original Message-----
From: Discussion list for Java 2D API
[mailto:JAVA2D-INTEREST@JAVA.SUN.COM] On Behalf Of David Kavanagh
Sent: Friday, June 10, 2005 8:05 AM
To: JAVA2D-INTEREST@JAVA.SUN.COM
Subject: Re: [JAVA2D] animating Swing components

This is a good topic. I tried this last year with a text field. I wanted
to have a marquee style widget for displaying text that is longer than
the box provided. I ran a background thread that simply updated the
text displayed at some preset intervals. (yes, I used invokeAndWait()
from the background thread) I ran into problems with the UI not updating
smoothly and I thought I had to much CPU being used. I even had my
background thread sleeping for over 1/2 second between updates. I never
spent much time debugging, so I'm nut sure what the right answer is.

David

Thus Spoke Rob Ross:

> Hi.
>
> This is (mostly) off-topic, but maybe someone can point me to the
> proper place to ask this.
>
> I am comfortable creating animations in general by using Java 2D
> drawing and background threads.
>
> I'm not sure how to apply some of these concepts when using Swing
> components, however.
>
> One thing I'd like to animate is a JSplitPane, so when a user clicks a

> button or chooses a menu item, the JSplitPane will be adjust to some
> certain size, but I don't want to just "jump" to the new size. I want
> to see the JSplitPane scroll in real-time to its final size.
>
> There are other such animations I'd like to do, like scrolling a
> JTable or JTree to some specific position, while showing all the
> intermediate scroll positions to the user.
>
> Any pointers?
>
> Thanks,
>
>
> Rob Ross, Senior Software Engineer
> E! Networks
> rross@eentertainment.com
> ---------------------------------------------------
> "Beware of he who would deny you access to information, for in his
> heart he dreams himself your master." -- Commissioner Pravin Lal
>
> ======================================================================
> =====
>
> To unsubscribe, send email to listserv@java.sun.com and include in the

> body of the message "signoff JAVA2D-INTEREST". For general help, send
> email to
> listserv@java.sun.com and include in the body of the message "help".

========================================================================
===
To unsubscribe, send email to listserv@java.sun.com and include in the
body of the message "signoff JAVA2D-INTEREST". For general help, send
email to listserv@java.sun.com and include in the body of the message
"help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

David Kavanagh

I agree that the swing timer seems like the better approach. I never
really looked at that before. I just had a look at the documentation and
source code and it seems like it ends up doing the same thing I was
which is submitting user code to run on the event thread at predefined
intervals. Whlie I'm not sure it will help my code run better, I'm sure
it will make my code look nicer because it handles things that I coded
explicitly. I'll give it a try when I get time to play with this again.
Thanks
David

Thus Spoke Ted Hill:

>Instead of using invokeAndWait from a background thread, I think using a
>Swing Timer would be a better choice.
>
>See:
>
>http://java.sun.com/docs/books/tutorial/uiswing/misc/timer.html
>
>
>-----Original Message-----
>From: Discussion list for Java 2D API
>[mailto:JAVA2D-INTEREST@JAVA.SUN.COM] On Behalf Of David Kavanagh
>Sent: Friday, June 10, 2005 8:05 AM
>To: JAVA2D-INTEREST@JAVA.SUN.COM
>Subject: Re: [JAVA2D] animating Swing components
>
>
>This is a good topic. I tried this last year with a text field. I wanted
>to have a marquee style widget for displaying text that is longer than
>the box provided. I ran a background thread that simply updated the
>text displayed at some preset intervals. (yes, I used invokeAndWait()
>from the background thread) I ran into problems with the UI not updating
>smoothly and I thought I had to much CPU being used. I even had my
>background thread sleeping for over 1/2 second between updates. I never
>spent much time debugging, so I'm nut sure what the right answer is.
>
>David
>
>Thus Spoke Rob Ross:
>
>
>
>>Hi.
>>
>>This is (mostly) off-topic, but maybe someone can point me to the
>>proper place to ask this.
>>
>>I am comfortable creating animations in general by using Java 2D
>>drawing and background threads.
>>
>>I'm not sure how to apply some of these concepts when using Swing
>>components, however.
>>
>>One thing I'd like to animate is a JSplitPane, so when a user clicks a
>>
>>
>
>
>
>>button or chooses a menu item, the JSplitPane will be adjust to some
>>certain size, but I don't want to just "jump" to the new size. I want
>>to see the JSplitPane scroll in real-time to its final size.
>>
>>There are other such animations I'd like to do, like scrolling a
>>JTable or JTree to some specific position, while showing all the
>>intermediate scroll positions to the user.
>>
>>Any pointers?
>>
>>Thanks,
>>
>>
>>Rob Ross, Senior Software Engineer
>>E! Networks
>>rross@eentertainment.com
>>---------------------------------------------------
>>"Beware of he who would deny you access to information, for in his
>>heart he dreams himself your master." -- Commissioner Pravin Lal
>>
>>======================================================================
>>=====
>>
>>To unsubscribe, send email to listserv@java.sun.com and include in the
>>
>>
>
>
>
>>body of the message "signoff JAVA2D-INTEREST". For general help, send
>>email to
>>listserv@java.sun.com and include in the body of the message "help".
>>
>>
>
>========================================================================
>===
>To unsubscribe, send email to listserv@java.sun.com and include in the
>body of the message "signoff JAVA2D-INTEREST". For general help, send
>email to listserv@java.sun.com and include in the body of the message
>"help".
>
>===========================================================================
>To unsubscribe, send email to listserv@java.sun.com and include in the body
>of the message "signoff JAVA2D-INTEREST". For general help, send email to
>listserv@java.sun.com and include in the body of the message "help".
>
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".
[att1.html]

Chet Haase

David and Ted: You might also check out the Timing Framework project
on java.net (http://timingframework.dev.java.net); I wrote this as
an example of using timers (see the associated article as well), but
also as a utility layer on top of the existing Timer facilities.
I hope to add more functionality to it as I get time, but in
the meantime I find it a bit easier to use that the Swing timer
for the kinds of stuff I do. (for example: it calls your
callback function with a float fraction that represents the
amount of the duration that's expired, and it lets you set
a total duration after which it automatically stops).

Rob: I'm talking about this very subject
(animating Swing components) in the "Advanced 2D" session
at JavaOne, so c'mon by if you're at the show. Also, come by
the "Ask the Experts" forum on Monday evening (630-800) and
the 2D and Swing BOFs on Tuesday nights; other good places to
pick our brains on this and other subjects...

Chet.

David Kavanagh wrote:
> I agree that the swing timer seems like the better approach. I never
> really looked at that before. I just had a look at the documentation and
> source code and it seems like it ends up doing the same thing I was
> which is submitting user code to run on the event thread at predefined
> intervals. Whlie I'm not sure it will help my code run better, I'm sure
> it will make my code look nicer because it handles things that I coded
> explicitly. I'll give it a try when I get time to play with this again.
> Thanks
> David
>
> Thus Spoke Ted Hill:
>
>>Instead of using invokeAndWait from a background thread, I think using a
>>Swing Timer would be a better choice.
>>
>>See:
>>
>>http://java.sun.com/docs/books/tutorial/uiswing/misc/timer.html
>>
>>
>>-----Original Message-----
>>From: Discussion list for Java 2D API
>>===========================================================================
>>To unsubscribe, send email to listserv@java.sun.com and include in the body
>>of the message "signoff JAVA2D-INTEREST". For general help, send email to
>>listserv@java.sun.com and include in the body of the message "help".
>>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Rob Ross

On Jun 10, 2005, at 8:24 AM, Chet Haase wrote:

>
> Rob: I'm talking about this very subject
> (animating Swing components) in the "Advanced 2D" session
> at JavaOne, so c'mon by if you're at the show. Also, come by
> the "Ask the Experts" forum on Monday evening (630-800) and
> the 2D and Swing BOFs on Tuesday nights; other good places to
> pick our brains on this and other subjects...
>
> Chet.
>

Hey that's great! I plan on being there.

Rob Ross, Senior Software Engineer
E! Networks
rross@eentertainment.com
---------------------------------------------------
"Beware of he who would deny you access to information, for in his
heart he dreams himself your master." -- Commissioner Pravin Lal

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

karsten
Offline
Joined: 2003-06-11

Hi,

I provide a framework for time-based animations in Java,
see https://animation.dev.java.net/

An article that explains time-based animations and
how this has been done in Java, is on my articles pages:
http://www.jgoodies.com/articles/

Time-based animations can define continous movements
without caring how fast the actual rendering happends.

Hope this helps. Best regards,
Karsten Lentzsch

David Kavanagh

This is a good topic. I tried this last year with a text field. I wanted
to have a marquee style widget for displaying text that is longer than
the box provided. I ran a background thread that simply updated the
text displayed at some preset intervals. (yes, I used invokeAndWait()
from the background thread)
I ran into problems with the UI not updating smoothly and I thought I
had to much CPU being used. I even had my background thread sleeping for
over 1/2 second between updates. I never spent much time debugging, so
I'm nut sure what the right answer is.

David

Thus Spoke Rob Ross:

> Hi.
>
> This is (mostly) off-topic, but maybe someone can point me to the
> proper place to ask this.
>
> I am comfortable creating animations in general by using Java 2D
> drawing and background threads.
>
> I'm not sure how to apply some of these concepts when using Swing
> components, however.
>
> One thing I'd like to animate is a JSplitPane, so when a user clicks
> a button or chooses a menu item, the JSplitPane will be adjust to
> some certain size, but I don't want to just "jump" to the new size. I
> want to see the JSplitPane scroll in real-time to its final size.
>
> There are other such animations I'd like to do, like scrolling a
> JTable or JTree to some specific position, while showing all the
> intermediate scroll positions to the user.
>
> Any pointers?
>
> Thanks,
>
>
> Rob Ross, Senior Software Engineer
> E! Networks
> rross@eentertainment.com
> ---------------------------------------------------
> "Beware of he who would deny you access to information, for in his
> heart he dreams himself your master." -- Commissioner Pravin Lal
>
> ===========================================================================
>
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body
> of the message "signoff JAVA2D-INTEREST". For general help, send
> email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".