void () { int index = tabPane.getSelectedIndex(); JViewport viewport = getScrollableTabViewport(); if (viewport == null || rects.length <= index || index < 0) return; Dimension viewSize = viewport.getViewSize(); Rectangle viewRect = viewport.getViewRect(); Rectangle tabRect = rects[index]; if (viewRect.contains(tabRect)) return; Point tabViewPosition = new Point(); int location; Dimension extentSize; if (isTopBottom()) { location = tabRect.x < viewRect.x ? tabRect.x : tabRect.x + tabRect.width - viewRect.width; viewport.setViewPosition(new Point(Math.max(0, Math.min(viewSize.width - viewRect.width, location)), tabRect.y)); tabViewPosition.x = index == 0 ? 0 : tabRect.x; extentSize = new Dimension(viewSize.width - tabViewPosition.x, viewRect.height); } else { location = tabRect.y < viewRect.y ? tabRect.y : tabRect.y + tabRect.height - viewRect.height; viewport.setViewPosition(new Point(tabRect.x, Math.max(0, Math.min(viewSize.height - viewRect.height, location)))); tabViewPosition.y = index == 0 ? 0 : tabRect.y; extentSize = new Dimension(viewRect.width, viewSize.height - tabViewPosition.y); } viewport.setExtentSize(extentSize); PointerInfo info = MouseInfo.getPointerInfo(); if (info != null) { Point mouseLocation = info.getLocation(); SwingUtilities.convertPointFromScreen(mouseLocation, tabPane); int oldHoverTab = hoverTab; hoverTab = tabForCoordinate(tabPane, mouseLocation.x, mouseLocation.y); if (oldHoverTab != hoverTab) { tabPane.repaint(); } } }