Skip to content

Commit

Permalink
Add a toImageIcon method to Swing FontIcon. Fixes #86
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Sep 9, 2020
1 parent 4039dd7 commit ff1ac74
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.kordamp.ikonli.IkonHandler;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
Expand Down Expand Up @@ -90,6 +91,16 @@ public void paintIcon(Component c, Graphics g, int x, int y) {
}
}

public ImageIcon toImageIcon() {
return toImageIcon(this);
}

public ImageIcon toImageIcon(Icon icon) {
BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(null, image.getGraphics(), 0, 0);
return new ImageIcon(image);
}

public Ikon getIkon() {
return ikon;
}
Expand Down

0 comments on commit ff1ac74

Please sign in to comment.