Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i recalculate preferred size of a JComponent?

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?

like image 865
William Wino Avatar asked Jan 11 '12 07:01

William Wino


1 Answers

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

like image 197
Tormod Avatar answered Sep 18 '22 00:09

Tormod