void () { myButton.setMargin(JBInsets.emptyInsets()); Dimension size = myButton.getPreferredSize(); Dimension iconSize = myCloseButton.getPreferredSize(); Dimension tagSize = new Dimension(size.width + iconSize.width - ourInset * 2, size.height); setPreferredSize(tagSize); myButton.setBounds(new Rectangle(tagSize)); myButton.setMargin(JBUI.insetsRight(iconSize.width)); Point p = new Point(tagSize.width - iconSize.width - ourInset * 3, (tagSize.height - iconSize.height) / 2 + JBUI.scale(1)); myCloseButton.setBounds(new Rectangle(p, iconSize)); }