protected int calculateTabWidth(int tabPlacement,int tabIndex,FontMetrics metrics){
  boolean calculate=!(tabPlacement == TOP || tabPlacement == BOTTOM);
  if (getTextViewForTab(tabIndex) != null)   calculate=false;
  String title=tabPane.getTitleAt(tabIndex);
  int pos=title.indexOf(' ');
  if (calculate && pos == -1)   calculate=false;
  if (!calculate)   return super.calculateTabWidth(tabPlacement,tabIndex,metrics);
  Icon icon=getIconForTab(tabIndex);
  Insets tabInsetsLocal=getTabInsets(tabPlacement,tabIndex);
  int width=tabInsetsLocal.left + tabInsetsLocal.right + 3;
  if (icon != null)   width+=icon.getIconWidth() + textIconGap;
  String firstLine=title.substring(0,pos);
  String secondLine=title.substring(pos + 1);
  width+=Math.max(SwingUtilities.computeStringWidth(metrics,firstLine),SwingUtilities.computeStringWidth(metrics,secondLine));
  return width;
}

protected int calculateTabWidth ( int tabPlacement , int tabIndex , FontMetrics metrics ) { boolean calculate = ! ( tabPlacement == TOP || tabPlacement == BOTTOM ) ; if ( getTextViewForTab ( tabIndex ) != null ) calculate = false ; String title = tabPane . getTitleAt ( tabIndex ) ; int pos = title . indexOf ( ' ' ) ; if ( calculate && pos == - 1 ) calculate = false ; if ( ! calculate ) return super . calculateTabWidth ( tabPlacement , tabIndex , metrics ) ; Icon icon = getIconForTab ( tabIndex ) ; Insets tabInsetsLocal = getTabInsets ( tabPlacement , tabIndex ) ; int width = tabInsetsLocal . left + tabInsetsLocal . right + 3 ; if ( icon != null ) width += icon . getIconWidth ( ) + textIconGap ; String firstLine = title . substring ( 0 , pos ) ; String secondLine = title . substring ( pos + 1 ) ; width += Math . max ( SwingUtilities . computeStringWidth ( metrics , firstLine ) , SwingUtilities . computeStringWidth ( metrics , secondLine ) ) ; return width ; }
calculate tab width . we may have to overwrite to adjust width for tabhirarchylevel
