What is the difference between setSize and setBounds?

Asked

Viewed 2,269 times

6

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

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, the setBounds is a way to define position and size at the same time, while the setSize sets only the size and the setLocation only the position.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.