Dimension () { if (myAnimated) { return myContent.getPreferredSize(); } if (myCurrentImage == null) { Dimension size = myContent.getPreferredSize(); int width = (myHorizontal && myExpand) ? myAnimationIterationStep : size.width; int height = (!myHorizontal && myExpand) ? myAnimationIterationStep : size.height; return new Dimension(width, height); } return new Dimension(myCurrentImage.getWidth(), myCurrentImage.getHeight()); }