getPreferredSize
The getPreferredSize method is a fundamental part of the Java Swing and AWT graphical user interface toolkits. It is a method of the Component class, which is the superclass of all graphical elements in Swing and AWT, including buttons, labels, panels, and more. The primary purpose of getPreferredSize is to inform the layout manager of a container about the ideal dimensions a component would like to occupy.
When a container's layout manager needs to arrange its child components, it typically queries each component
For example, a JButton might return the size needed to display its text and icon with some