void (ActionEvent event) { JViewport viewport = getScrollableTabViewport(); if (viewport == null) return; Map<Integer, Rectangle> invisibleTabs = new LinkedHashMap<>(); for (int i = 0; i < tabPane.getTabCount(); i++) { Rectangle rectangle = rects[i]; if (!viewport.getViewRect().contains(rectangle)) invisibleTabs.put(i, rectangle); } JBPopupMenu menu = new JBPopupMenu(); for (Map.Entry<Integer, Rectangle> entry : invisibleTabs.entrySet()) { final int index = entry.getKey(); menu.add(new JMenuItem(tabPane.getTitleAt(index), tabPane.getIconAt(index)) { @Override protected void fireActionPerformed(ActionEvent event) { tabPane.setSelectedIndex(index); } }); } menu.show(this, 0, getHeight()); }