Search code examples
javaswinglayout-managerdimension

Dimension, Only changing the width/height


How do I only change the width or height of a component that requires a Dimension object? Currently I do it like this:

jbutton.setPreferredSize(new Dimension(button.getPreferredSize().width, 100));

But I have a feeling that I'm doing it the wrong way. What is the best way to approach this if there is a better way?


Solution

  • I ended up doing it the way Kleopatra said. Not changing the preferredSize but letting the layout manager do the job. Since this is the proper way to change the size of a component.