How does the object to be scrolled report its actual size to the JScrollPane?
1. By implementing the javax.swing.Scrollable interface;
2. By its getPreferredSize() method.
The first case is used by components such as JTable, JTree, and JTextArea.
The second is used, for instance, when you place a JPanel in a JScrollPane. The scrollpane will use the preferred size of the panel to decide if scrolling is needed or not.