What is the difference between setSize and setBounds?

6

What is the difference in Java Swing between setSize and setBounds ?

    
asked by anonymous 13.07.2015 / 02:26

1 answer

5

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.

    
13.07.2015 / 02:38