0

In all my time so far working with Java and its Swing GUI framework, I've never quite figured out (or even attempted to try) how to make the interface animate components.

Say I wanted the screen to slide left into the next screen or have a JLabel "fly" to a new location. Perhaps you want a menu to smoothly open in an animated fashion. How does this work?

Do you have to use SwingWorker? Even if that's the case... how can you control the painting of components if the layout manager is already doing that?

bgroenks
  • 1,859
  • 5
  • 34
  • 63
  • 1
    As you should, but if you are not getting good answers you either have to tune the question or offer a bounty. – Paul Feb 05 '12 at 19:50
  • But what if I don't want to give up reputation haha. But seriously... what exactly is the cost of that? Do you lose privileges? – bgroenks Feb 05 '12 at 19:52
  • See http://stackoverflow.com/questions/how-to-ask, also http://stackoverflow.com/faq#bounty – Paul Feb 05 '12 at 19:55

3 Answers3

4

Have a look at the book Filthy Rich Clients, you will find some really good answers there.

Paul
  • 19,704
  • 14
  • 78
  • 96
stryba
  • 1,979
  • 13
  • 19
  • This is an excellent book. I heard the authors speak at Java One on the topic and they were as entertaining and informative as the book. Too bad they were assimilated by Google and now write for the small screen (Android). – Paul Feb 05 '12 at 18:26
  • +1, Highly recommend purchasing this book! I own it myself. :D – mre Feb 05 '12 at 18:39
2

I think that there no reason for use SwingWorker, SwingWorker is designated for running long Backgroung Task(s) on output would be on Event dispatch Thread,

For animations in Swing is there javax.swing.Timer, examples here

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • Yes but this involves a bit more than just timing animations from a pure paintComponent override. I'm thinking more in terms of interpolation. – bgroenks Feb 05 '12 at 19:48
  • @ghostsoldier23: In general, use `javax.swing.Timer` to iterate a _view_; use `SwingWorker` to iterate a _model_. – trashgod Feb 05 '12 at 21:31
2

Take a look at Trident library. You can use it to interpolate various properties in your class.

tenorsax
  • 21,123
  • 9
  • 60
  • 107
  • Interesting. It handles this based on the concept of timelines? – bgroenks Feb 05 '12 at 19:47
  • @ghostsoldier23, yes, timelines and timeline scenarios, check webstart [demos](http://www.pushing-pixels.org/2009/06/25/trident-part-8-timeline-scenarios.html) – tenorsax Feb 05 '12 at 20:02