void (String labelText) { label.setText(StringUtil.isNotEmpty(labelText) ? labelText : " "); if (StringUtil.isNotEmpty(labelText)) { Dimension size = comment.getPreferredSize(); size.width = label.getMinimumSize().width; comment.setMinimumSize(size); if (text2 != null) { text2.setMinimumSize(size); } } }