TagButton (TagButton replaceButton, DnDEvent event) { int i = myTags.indexOf(replaceButton); if (i > myTags.indexOf(event.getAttachedObject())) { return replaceButton; } return ContainerUtil.findLast(myTags, button -> button.isVisible() && myTags.indexOf(button) < i); }