public Dimension getPreferredSize() {
        Insets i = getInsets();
        return new Dimension(i.left + i.right + 2 + (image != null && text != null && textVisible ? textImageGap : 0)
                        + (image != null ? image.getWidth(this) : 0)
                        + (metrics != null && textVisible && text != null ? metrics.stringWidth(text) : 0), i.top + i.bottom
                        + Math.max(image != null ? image.getHeight(this) : 0, (metrics != null ? metrics.getHeight() : 0)));
    }