| 676 | /// |
| 677 | /// - `icon`: the image that the label presents. |
| 678 | @Override |
| 679 | public void setIcon(Image icon) { |
| 680 | if (this.icon == icon) { //NOPMD CompareObjectsWithEquals |
| 681 | return; |
| 682 | } |
| 683 | if (this.icon != null) { |
| 684 | this.icon.removeActionListener(iconChangeListener); |
| 685 | iconChangeListenerInstalled = false; |
| 686 | } |
| 687 | widthAtLastCheck = -1; |
| 688 | if (icon != null) { |
| 689 | if (icon.requiresDrawImage()) { |
| 690 | legacyRenderer = true; |
| 691 | } |
| 692 | |
| 693 | if (mask != null) { |
| 694 | maskedIcon = icon.applyMaskAutoScale(mask); |
| 695 | } |
| 696 | } |
| 697 | this.icon = icon; |
| 698 | if (this.icon != null) { |
| 699 | if (isInitialized()) { |
| 700 | this.icon.addActionListener(iconChangeListener); |
| 701 | iconChangeListenerInstalled = true; |
| 702 | } |
| 703 | } |
| 704 | setShouldCalcPreferredSize(true); |
| 705 | checkAnimation(); |
| 706 | repaint(); |
| 707 | } |
| 708 | |
| 709 | /// Returns the vertical alignment of the Label, this will only work when the icon |
| 710 | /// is in the side of the text and not above or below it. |