Dimension ( JComponent comp, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap ) { JMenu jMenu = (JMenu)comp; Icon icon1 = getIcon(); Icon icon2 = getAllowedIcon(); checkEmptyIcon(comp); String text = jMenu.getText(); Font font = jMenu.getFont(); FontMetrics fontmetrics = jMenu.getToolkit().getFontMetrics(font); resetRects(); layoutMenuItem( fontmetrics, text, icon1, icon2, arrowIcon, jMenu.getVerticalAlignment(), jMenu.getHorizontalAlignment(), jMenu.getVerticalTextPosition(), jMenu.getHorizontalTextPosition(), ourViewRect, ourIconRect, ourTextRect, ourAcceleratorRect, ourCheckIconRect, ourArrowIconRect, text != null ? defaultTextIconGap : 0, defaultTextIconGap ); Rectangle ourPreferredSizeRect = new Rectangle(); ourPreferredSizeRect.setBounds(ourTextRect); SwingUtilities.computeUnion(ourIconRect.x, ourIconRect.y, ourIconRect.width, ourIconRect.height, ourPreferredSizeRect); if (useCheckAndArrow()){ ourPreferredSizeRect.width += myMaxGutterIconWidth; ourPreferredSizeRect.width += defaultTextIconGap; ourPreferredSizeRect.width += defaultTextIconGap; ourPreferredSizeRect.width += ourArrowIconRect.width; } ourPreferredSizeRect.width += 2 * defaultTextIconGap; Insets insets = jMenu.getInsets(); if (insets != null){ ourPreferredSizeRect.width += insets.left + insets.right; ourPreferredSizeRect.height += insets.top + insets.bottom; } if (ourPreferredSizeRect.width % 2 == 0){ ourPreferredSizeRect.width++; } if (ourPreferredSizeRect.height % 2 == 0){ ourPreferredSizeRect.height++; } return patchPreferredSize(comp, ourPreferredSizeRect.getSize()); }