See the Javadoc of the FlowLayout
:
A flow layout lets each component assume its natural (preferred) size
Since you do some custom painting, the BallPanel
cannot compute its preferred size (which is based on the components you add the panel). So override in the BallPanel
class the getPreferredSize
method to return correct dimensions (correct means matching your custom painting). Consider doing the same for the getMinimumSize
and getMaximumSize
.
What I always use when I have to debug Swing layout problems is to add borders to my components in specific colors. That way you clearly see the size your components take in their parent container, which might be a good starting point for debugging. In your case, it would show a very tiny panel ;-)