What is the difference in Java Swing between setSize
and setBounds
?
What is the difference in Java Swing between setSize
and setBounds
?
These two codes are practically equivalent:
int x = ..., y = ..., w = ..., h = ...;
JComponent x = ...;
x.setBounds(x, y, w, h);
int x = ..., y = ..., w = ..., h = ...;
JComponent x = ...;
x.setSize(w, h);
x.setLocation(x, y);
That is, setBounds
is a way to define position and size at the same time, whereas setSize
only defines size and setLocation
only position.