I'm looking for a reset size of the scrolling of a Jpanel after resizing.
I do my calculation with the size of labels displayed
The size is just for multiples of two, but not for others.
I don't see how to solve my problem
Here is my code
The paintComponent() method is used for custom painting, not for setting the preferred size of the component. You should definitely not be invoking revalidate() and setPreferredSize() from within that method. In fact there is no reason for you to override the paintComponent() method at all.
You should NOT be using setPreferredSize() anywhere in your code. Setting the preferred size is the job of the layout manager.
If you use an appropriate layout manager the preferred size will be determined for you and scrolling will work properly. Read the Swing tutorial on Layout Managers for more information and examples.
Rob Camick wrote:The paintComponent() method is used for custom painting, not for setting the preferred size of the component. You should definitely not be invoking revalidate() and setPreferredSize() from within that method. In fact there is no reason for you to override the paintComponent() method at all.
You should NOT be using setPreferredSize() anywhere in your code. Setting the preferred size is the job of the layout manager.
If you use an appropriate layout manager the preferred size will be determined for you and scrolling will work properly. Read the Swing tutorial on Layout Managers for more information and examples.
Actually my design method is to be the best (I'm newbie in java).
Thank you for the link. I used a JGridLayout GridLayout