int index = tabForCoordinate(tabPane, x, y);    if (index != -1 && tabPane.isEnabledAt(index)) tabPane.setSelectedIndex(index); tabPane.revalidate(); tabPane.repaint(); }
    public void mousePressed(MouseEvent e)    {      int x = e.getX();      int y = e.getY();      int tabCount = tabPane.getTabCount();      if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT)        {          if (e.getSource() == incrButton)            {              if (++currentScrollLocation >= tabCount)                currentScrollLocation = tabCount - 1;                            int width = 0;              for (int i = currentScrollLocation - 1; i < tabCount; i++)                width += rects[i].width;              if (width < viewport.getWidth())                // FIXME: Still getting mouse events after the button is disabled.                //	incrButton.setEnabled(false);                currentScrollLocation--;              else if (! decrButton.isEnabled())                decrButton.setEnabled(true);              tabPane.revalidate();              tabPane.repaint();              return;            }          else if (e.getSource() == decrButton)            {              if (--currentScrollLocation < 0)                currentScrollLocation = 0;              if (currentScrollLocation == 0)                decrButton.setEnabled(false);              else if (! incrButton.isEnabled())                incrButton.setEnabled(true);              tabPane.revalidate();              tabPane.repaint();              return;            }        }      int index = tabForCoordinate(tabPane, x, y);      // We need to check since there are areas where tabs cannot be      // e.g. in the inset area.      if (index != -1 && tabPane.isEnabledAt(index))        tabPane.setSelectedIndex(index);      tabPane.revalidate();      tabPane.repaint();    }