@Override
public void mouseDragged(MouseEvent e) {
// Gets the tab index based on the mouse position
if (!isDragging) {
TabbedPane pane = TabbedPane.this;
TabbedPaneUI paneUI = pane.getUI();
dragIndex = paneUI.tabForCoordinate(pane, e.getX(), e.getY());
if (dragIndex >= 0) {
Rectangle bounds = paneUI.getTabBounds(pane, dragIndex);
// Paint the tabbed pane to a buffer
Image totalImage = new BufferedImage(getWidth(), getHeight(),
BufferedImage.TYPE_INT_ARGB);
Graphics totalGraphics = totalImage.getGraphics();
totalGraphics.setClip(bounds);