Dimension, Only changing the width/height

First of all you are not changing the dimension of JButton. You are specifying the desired preferred size, that can be eventually applied to your JButton depending on the LayoutManager of the component it's inserted into.

For what concern the use of Dimension object that's fine. Eventually you can access directly Dimension field:

Dimension d = button.getPreferredSize();
d.height = 10;
jbutton.setPreferredSize(d); 

but that's pretty much the same thing.


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.