public void mouseClicked(MouseEvent e) { int x = e.getX(); int y = e.getY(); int currentTabIndex = -1; int tabCount = tabPane.getTabCount(); for (int i = 0; i < tabCount; i++) { if (rects[i].contains(x, y)) { currentTabIndex = i; break; } // if contains } // for i if (currentTabIndex >= 0) { Rectangle tabRect = rects[currentTabIndex]; x = x - tabRect.x; y = y - tabRect.y; if ((x >= 5) && (x <= 15) && (y >= 5) && (y <= 15)) { try { tabbedPane.remove(currentTabIndex); } catch (Exception ex) { ex.printStackTrace(); } } // if } // if currentTabIndex >= 0 System.gc(); } // mouseClicked