void (final int charCount) { JComponent comp = getChildComponent(); Dimension size = GuiUtils.getSizeByChars(charCount, comp); comp.setPreferredSize(size); Dimension preferredSize = myBrowseButton.getPreferredSize(); boolean keepHeight = UIUtil.isUnderWin10LookAndFeel(); preferredSize.setSize(size.width + preferredSize.width + 2, keepHeight ? preferredSize.height : preferredSize.height + 2); setPreferredSize(preferredSize); }