Creating Custom Icon via ICon Interface

Java Swing provides Icon interface and any class which implements it is an icon & this way we can create custom icon. The Icon interface will ask you to implement three methods to decide the size of the icon and to perform icon drawing. In this example, we will create rectangle icon and use it with the JLabel component.