private void paintIconAlignedCenter(Component c, Graphics g, int x, int y, @NotNull Icon icon) { int iconHeight = getIconHeight(); icon.paintIcon(c, g, x, y + (iconHeight - icon.getIconHeight()) / 2); }
/** * Sets given icon to display between checkbox icon and text. * * @return true in case of success and false otherwise */ public boolean setTextIcon(@NotNull Icon icon) { if (UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF()) { return false; } ButtonUI ui = getUI(); if (ui instanceof BasicRadioButtonUI) { Icon defaultIcon = ((BasicRadioButtonUI) ui).getDefaultIcon(); if (defaultIcon != null) { MergedIcon mergedIcon = new MergedIcon(defaultIcon, 10, icon); setIcon(mergedIcon); return true; } } return false; }
@Override public void paintIcon(Component c, Graphics g, int x, int y) { paintIconAlignedCenter(c, g, x, y, myLeftIcon); paintIconAlignedCenter(c, g, x + myLeftIcon.getIconWidth() + myHorizontalStrut, y, myRightIcon); }