Swing
Introduction
Component class
Set methods of the Component class
Method | Description |
---|---|
setSize(intWidth, intHeight) | Resizes this component using two int values. |
setLocation(intX, intY) | Moves this component to the x and y coordinates specified by two int values. |
setBounds(intX, intY, intWidth, intHeight) | Moves and resizes this component. |
setEnabled(boolean) | If the boolean value is true, the component is enabled. If false, the component is disabled, so it doesn't respond to user input or generate events. |
setVisible(boolean) | Shows this component if the boolean value is true. Otherwise, hides it. |
setFocusable(boolean) | Determines whether or not this component can receive the focus. |
setName(String) | Sets the name of this component to the specified string. |
Get methods of the Component class
Method | Description |
---|---|
getHeight() | Returns the height of this component as an int. |
getWidth() | Returns the width of this component as an int. |
getX() | Returns the x coordinate of this component as an int. |
getY() | Returns the y coordinate of this component as an int. |
getName() | Returns the name of this component as a String. |
Other methods of the Component class
Method | Description |
---|---|
isEnabled() | Returns true if the component is enabled. |
isVisible() | Returns true if the component is visible. |
requestFocusInWindow() | Moves the focus to the component. |
Notes
- When you set the location and size of a component, the unit of measurement is pixels, which is the number of dots that your monitor uses to display a screen.
- The preferred way to set the location of a component is to use a layout manager.