if ((m.isSelected() && checkIcon == null) || m.getModel().isArmed()
ButtonModel mod = m.getModel(); if ((m.isSelected() && checkIcon == null) || (mod != null && mod.isArmed())
  protected void paintMenuItem(Graphics g, JComponent c, Icon checkIcon,                               Icon arrowIcon, Color background,                               Color foreground, int defaultTextIconGap)  {    JMenuItem m = (JMenuItem) c;    Rectangle tr = new Rectangle(); // text rectangle    Rectangle ir = new Rectangle(); // icon rectangle    Rectangle vr = new Rectangle(); // view rectangle    Rectangle br = new Rectangle(); // border rectangle    Rectangle ar = new Rectangle(); // accelerator rectangle    Rectangle cr = new Rectangle(); // checkIcon rectangle    int vertAlign = m.getVerticalAlignment();    int horAlign = m.getHorizontalAlignment();    int vertTextPos = m.getVerticalTextPosition();    int horTextPos = m.getHorizontalTextPosition();    Font f = m.getFont();    g.setFont(f);    FontMetrics fm = g.getFontMetrics(f);    SwingUtilities.calculateInnerArea(m, br);    SwingUtilities.calculateInsetArea(br, m.getInsets(), vr);    paintBackground(g, m, m.getBackground());    /*     * MenuItems insets are equal to menuItems margin, space between text and     * menuItems border. We need to paint insets region as well.     */    Insets insets = m.getInsets();    br.x -= insets.left;    br.y -= insets.top;    br.width += insets.right + insets.left;    br.height += insets.top + insets.bottom;    // Menu item is considered to be highlighted when it is selected.    // But we don't want to paint the background of JCheckBoxMenuItems    if ((m.isSelected() && checkIcon == null) || m.getModel().isArmed()        && (m.getParent() instanceof MenuElement))      {        if (m.isContentAreaFilled())          {            g.setColor(selectionBackground);            g.fillRect(br.x, br.y, br.width, br.height);          }      }    else      {        if (m.isContentAreaFilled())          {            g.setColor(m.getBackground());            g.fillRect(br.x, br.y, br.width, br.height);          }      }    // If this menu item is a JCheckBoxMenuItem then paint check icon    if (checkIcon != null)      {        SwingUtilities.layoutCompoundLabel(m, fm, null, checkIcon, vertAlign,                                           horAlign, vertTextPos, horTextPos,                                           vr, cr, tr, defaultTextIconGap);        checkIcon.paintIcon(m, g, cr.x, cr.y);        // We need to calculate position of the menu text and position of        // user menu icon if there exists one relative to the check icon.        // So we need to adjust view rectangle s.t. its starting point is at        // checkIcon.width + defaultTextIconGap.        vr.x = cr.x + cr.width + defaultTextIconGap;      }    // if this is a submenu, then paint arrow icon to indicate it.    if (arrowIcon != null && (c instanceof JMenu))      {        if (!((JMenu) c).isTopLevelMenu())          {            int width = arrowIcon.getIconWidth();            int height = arrowIcon.getIconHeight();            int offset = (vr.height - height) / 2;            arrowIcon.paintIcon(m, g, vr.width - width, vr.y + offset);          }      }    // paint text and user menu icon if it exists    Icon i = m.getIcon();    SwingUtilities.layoutCompoundLabel(c, fm, m.getText(), i, vertAlign,                                       horAlign, vertTextPos, horTextPos, vr,                                       ir, tr, defaultTextIconGap);    if (i != null)      i.paintIcon(c, g, ir.x, ir.y);    paintText(g, m, tr, m.getText());    // paint accelerator    String acceleratorText = "";    if (m.getAccelerator() != null)      {        acceleratorText = getAcceleratorText(m.getAccelerator());        fm = g.getFontMetrics(acceleratorFont);        ar.width = fm.stringWidth(acceleratorText);        ar.x = br.width - ar.width;        vr.x = br.width - ar.width - defaultTextIconGap;        SwingUtilities.layoutCompoundLabel(m, fm, acceleratorText, null,                                           vertAlign, horAlign, vertTextPos,                                           horTextPos, vr, ir, ar,                                           defaultTextIconGap);        paintAccelerator(g, m, ar, acceleratorText);      }  }