获取JTabbedPane选项卡区域边界
//package com.nowjava; import javax.swing.*;//时 代 J a v a 公 众 号 - nowjava.com import java.awt.*; public class Main { static Rectangle getTabAreaBounds(JTabbedPane tabbedPane) { Rectangle tabbedRect = tabbedPane.getBounds(); //pointed out by daryl. NullPointerException: i.e. addTab("Tab",null) //Rectangle compRect = getSelectedComponent().getBounds(); Component comp = tabbedPane.getSelectedComponent(); int idx = 0; while (comp == null && idx < tabbedPane.getTabCount()) { comp = tabbedPane.getComponentAt(idx++); }/**来 自 N o w J a v a . c o m - 时 代 Java**/ Rectangle compRect = (comp == null) ? new Rectangle() : comp .getBounds(); int tabPlacement = tabbedPane.getTabPlacement(); if (tabPlacement == SwingConstants.TOP) { tabbedRect.height = tabbedRect.height - compRect.height; } else if (tabPlacement == SwingConstants.BOTTOM) { tabbedRect.y = tabbedRect.y + compRect.y + compRect.height; tabbedRect.height = tabbedRect.height - compRect.height; } else if (tabPlacement == SwingConstants.LEFT) { tabbedRect.width = tabbedRect.width - compRect.width; }