Class AnimatedLayout

  • All Implemented Interfaces:
    LayoutManager, LayoutManager2


    public class AnimatedLayout
    extends Object
    implements LayoutManager2
    A layout that smoothly animates components as they need to move from one location to another.

    This is achieved by calling:
    myComponent.putClientProperty(DESTINATION, newDestination)

    This layout then nudges the component until it reaches that destination. The nudge is proportional to the distance that the component has to cover, giving the impression of a decelerating animation as the object approaches its destination.

    • Field Detail

      • DELAY

        public static int DELAY
        This is the delay, in milliseconds, between adjustments. I find 30 to be almost "too fast" and 50 almost "too slow".
    • Constructor Detail

      • AnimatedLayout

        public AnimatedLayout(boolean calculateMinimumSize)
    • Method Detail

      • addLayoutComponent

        public void addLayoutComponent(Component comp,
                                       Object constraints)
      • getLayoutAlignmentX

        public float getLayoutAlignmentX(Container target)
      • getLayoutAlignmentY

        public float getLayoutAlignmentY(Container target)
      • invalidateLayout

        public void invalidateLayout(Container target)
      • addLayoutComponent

        public void addLayoutComponent(String name,
                                       Component comp)
      • nudge

        protected static boolean nudge(JComponent c,
                                       Rectangle dest)
        Nudge a component towards the destination.
        Parameters:
        c - the component to nudge.
        dest - the target bounds for the component.
        Returns:
        true when the component is at the desired location
      • layoutContainer

        public void layoutContainer(Container parent)
      • runLayout

        protected static void runLayout(JComponent parent)
      • removeLayoutComponent

        public void removeLayoutComponent(Component comp)