Note that there are some explanatory texts on larger screens.

plurals
  1. POShould I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing?
    text
    copied!<p>Several times I've been criticized for having suggested the use of the following methods:</p> <ol> <li><strong>setPreferredSize</strong></li> <li><strong>setMinimumSize</strong></li> <li><strong>setMaximumSize</strong></li> </ol> <p>on <code>Swing</code> components. I don't see any alternative to their use when I want to define proportions between displayed components. I have been told this:</p> <blockquote> <p>With layouts the answer is always the same: use a suitable LayoutManager</p> </blockquote> <p>I have searched the web a little bit, but I haven't found any comprehensive analysis of the subject. So I have the following questions:</p> <ol> <li>Should I completely avoid the use of those methods?</li> <li>The methods have been defined for a reason. So when should I use them? In which context? For what purposes? </li> <li>What exactly are the negative consequences of using those methods? (I can only think adding portability between systems with different screen resolution).</li> <li>I don't think any LayoutManager can exactly satisfy all desired layout needs. Do I really need to implement a new LayoutManager for every little variation on my layout ? </li> <li>If the answer to 4 is "yes", won't this lead to a proliferation of LayoutManager classes which will become difficult to maintain?</li> <li>In a situation where I need to define proportions between children of a Component (eg, child1 should use 10% of space, child2 40% ,child3 50%), is it possible to achieve that without implementing a custom LayoutManager?</li> </ol> <p>I hope to have been clear.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload