TagButton (DnDEvent event) { Object object = event.getAttachedObject(); if (!(object instanceof TaskButton)) { return null; } Rectangle area = new Rectangle(event.getPoint().x - 5, event.getPoint().y - 5, 10, 10); TaskButton button = ContainerUtil.find(myTags, tag -> tag.isVisible() && tag.getBounds().intersects(area)); if (button == null || button == object) return null; boolean left = button.getBounds().getCenterX() > event.getPoint().x; int i = myTags.indexOf(button); if (i < myTags.indexOf(object)) { if (!left) { button = ContainerUtil.find(myTags, b -> b.isVisible() && myTags.indexOf(b) > i); } } else if (left) { button = ContainerUtil.findLast(myTags, b -> b.isVisible() && myTags.indexOf(b) < i); } return button == object ? null : button; }