Which method of the Component class is used to set the position and size of a component?

setBounds() method is used to set the position and size of a component.

In Core Java, the setBounds(int x, int y, int width, int height) method of the Component class is used to set the position and size of a component. This method allows you to specify the x and y coordinates of the component’s top-left corner, as well as its width and height. The syntax is:

java
public void setBounds(int x, int y, int width, int height)

Here, x and y represent the horizontal and vertical coordinates, respectively, and width and height represent the width and height of the component.