MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / setIcon

Method setIcon

CodenameOne/src/com/codename1/ui/FontImage.java:6966–6998  ·  view source on GitHub ↗
(IconHolder l, Font font, char icon, float size)

Source from the content-addressed store, hash-verified

6964 ///
6965 /// - `size`: the size of the icon in millimeters, or -1 to use the default height of the font
6966 public static void setIcon(IconHolder l, Font font, char icon, float size) {
6967 Style s = new Style(l.getIconStyleComponent().getUnselectedStyle());
6968 s.setFont(font.derive(rightSize(s, size), Font.STYLE_PLAIN));
6969 l.setIcon(FontImage.create("" + icon, s));
6970 if (l instanceof SelectableIconHolder) {
6971 SelectableIconHolder b = (SelectableIconHolder) l;
6972 Style sel = b.getIconStyleComponent().getSelectedStyle();
6973 Style pre = b.getIconStyleComponent().getPressedStyle();
6974 Style dis = b.getIconStyleComponent().getDisabledStyle();
6975 if (sel.getFgColor() != s.getFgColor() || (sel.getBgColor() != s.getBgColor()) || (sel.getBgTransparency() != s.getBgTransparency()) || (sel.getFgAlpha() != s.getFgAlpha())) {
6976 sel = new Style(sel);
6977 sel.setFont(font.derive(rightSize(sel, size), Font.STYLE_PLAIN));
6978 b.setRolloverIcon(FontImage.create("" + icon, sel));
6979 } else {
6980 b.setRolloverIcon(null);
6981 }
6982 if (pre.getFgColor() != s.getFgColor() || (pre.getBgColor() != s.getBgColor()) || (pre.getBgTransparency() != s.getBgTransparency()) || (pre.getFgAlpha() != s.getFgAlpha())) {
6983 pre = new Style(pre);
6984 pre.setFont(font.derive(rightSize(pre, size), Font.STYLE_PLAIN));
6985 b.setPressedIcon(FontImage.create("" + icon, pre));
6986 b.setRolloverPressedIcon(FontImage.create("" + icon, pre));
6987 } else {
6988 b.setPressedIcon(null);
6989 }
6990 if (dis.getFgColor() != s.getFgColor() || (dis.getBgColor() != s.getBgColor()) || (dis.getBgTransparency() != s.getBgTransparency()) || (dis.getFgAlpha() != s.getFgAlpha())) {
6991 dis = new Style(dis);
6992 dis.setFont(font.derive(rightSize(dis, size), Font.STYLE_PLAIN));
6993 b.setDisabledIcon(FontImage.create("" + icon, dis));
6994 } else {
6995 b.setDisabledIcon(null);
6996 }
6997 }
6998 }
6999
7000 /// Applies icon font from the font to the given label using the styling of the label.
7001 ///

Callers 5

setMaterialIconMethod · 0.95
setFontIconMethod · 0.95
startMethod · 0.95
startMethod · 0.95

Calls 15

setFontMethod · 0.95
rightSizeMethod · 0.95
createMethod · 0.95
getFgColorMethod · 0.95
getBgColorMethod · 0.95
getBgTransparencyMethod · 0.95
getFgAlphaMethod · 0.95
setRolloverIconMethod · 0.95
setPressedIconMethod · 0.95
setDisabledIconMethod · 0.95
minMethod · 0.95

Tested by 2

startMethod · 0.76