setIcon
setIcon is a method used in graphical user interface toolkits to assign an icon to a component, such as a button, menu item, toolbar item, or similar control. The exact name, signature, and accepted icon type vary by framework, but the general purpose is to replace or assign the visual symbol displayed by the element.
In most libraries, setIcon takes an icon or image object, a resource identifier, or a file path.
Examples in popular frameworks
- Java Swing: JButton has setIcon(Icon icon), where Icon can be an ImageIcon or other Icon implementation.
- Android: MenuItem and similar components offer setIcon(int resId) or setIcon(Drawable) to apply drawable resources.
- Qt: QToolButton and QPushButton provide setIcon(const QIcon&), with layout and size hints influenced by the icon.
- iOS/UIKit: UIButton supports setImage(UIImage?, forState: UIControlState) to display an image for different button states.
- GTK+: Buttons can use images via set_image or related image widgets bound to the button.
Considerations often include ensuring proper icon resolution for different densities, handling state changes (normal, pressed, disabled),