Dimension (JComponent c) { ToolbarComboWidget combo = (ToolbarComboWidget)c; Dimension res = new Dimension(); List<Icon> icons = combo.getLeftIcons(); boolean skipNextGap = false; if (!icons.isEmpty()) { res.width += calcIconsWidth(icons, combo.getLeftIconsGap()) + getGapAfterLeftIcons(); res.height = icons.stream().mapToInt(Icon::getIconHeight).max().orElse(0); skipNextGap = true; } if (!StringUtil.isEmpty(combo.getText())) { FontMetrics metrics = c.getFontMetrics(c.getFont()); String text = getText(combo); res.width += metrics.stringWidth(text); res.height = Math.max(res.height, metrics.getHeight()); skipNextGap = false; } icons = combo.getRightIcons(); if (!icons.isEmpty()) { if (res.width > 0 && !skipNextGap) res.width += getGapBeforeRightIcons(); res.width += calcIconsWidth(icons, combo.getRightIconsGap()); res.height = Math.max(res.height, icons.stream().mapToInt(Icon::getIconHeight).max().orElse(0)); skipNextGap = false; } if (isSeparatorShown(combo)) { res.width += 2 * getSeparatorGap() + SEPARATOR_WIDTH; skipNextGap = false; } if (combo.isExpandable()) { if (res.width > 0 && !skipNextGap) res.width += getGapBeforeExpandIcon(); res.width += EXPAND_ICON.getIconWidth(); res.height = Math.max(res.height, EXPAND_ICON.getIconHeight()); } Insets insets = c.getInsets(); res.height += insets.top + insets.bottom; res.width += insets.left + insets.right; res.width = Integer.min(maxWidth, res.width); return res; }