I know the fact that when I create an instance of a JComponent, it has it's own preferred size. Now let's suppose that I setPreferredSize that JComponent manually with a dimension of 0 x 0. And i want that Component to "reset" its own preferredSize. How do I do that?
1) Setting preferred size to null should reset the component back to getting its preferred size calculated as if it was never set.
component.setPreferredSize(null);
This might not do what you want, depending on how you signal that the layout should be redone - but at least it is technically the answer to your question.
2) It is generally advised to not use setPreferredSize, see this post
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With