int (Point point) { if (lastTableLayout == null) return -1; int result = -1; Component c = myTabs.getComponentAt(point); Set<TabInfo> lastInRow = new HashSet<>(); for (int i = 0; i < lastTableLayout.table.size(); i++) { List<TabInfo> columns = lastTableLayout.table.get(i).myColumns; if (!columns.isEmpty()) { lastInRow.add(columns.get(columns.size() - 1)); } } if (c instanceof JBTabsImpl) { for (int i = 0; i < lastTableLayout.myVisibleInfos.size() - 1; i++) { TabInfo firstInfo = lastTableLayout.myVisibleInfos.get(i); TabInfo secondInfo = lastTableLayout.myVisibleInfos.get(i + 1); TabLabel first = myTabs.getInfoToLabel().get(firstInfo); TabLabel second = myTabs.getInfoToLabel().get(secondInfo); Rectangle firstBounds = first.getBounds(); Rectangle secondBounds = second.getBounds(); final boolean between = firstBounds.getMaxX() < point.x && secondBounds.getX() > point.x && firstBounds.y < point.y && secondBounds.getMaxY() > point.y; if (between) { c = first; break; } if (lastInRow.contains(firstInfo) && firstBounds.y <= point.y && firstBounds.getMaxY() >= point.y && firstBounds.getMaxX() <= point.x) { c = second; break; } } } if (c instanceof TabLabel) { TabInfo info = ((TabLabel)c).getInfo(); int index = lastTableLayout.myVisibleInfos.indexOf(info); boolean isDropTarget = myTabs.isDropTarget(info); if (!isDropTarget) { for (int i = 0; i <= index; i++) { if (myTabs.isDropTarget(lastTableLayout.myVisibleInfos.get(i))) { index -= 1; break; } } result = index; } else if (index < lastTableLayout.myVisibleInfos.size()) { result = index; } } return result; }