Skip to content

Commit

Permalink
TabbedPane: improved/fixed placement of tab close button on smaller t…
Browse files Browse the repository at this point in the history
…ab insets or smaller tab height (PR #193)
  • Loading branch information
DevCharly committed Oct 26, 2020
1 parent 09c9835 commit c8d280f
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ protected void paintTabCloseButton( Graphics g, int tabIndex, int x, int y, int
bm.setPressed( rollover && isPressedTabClose() );

// paint tab close icon
Rectangle tabCloseRect = getTabCloseBounds( x, y, w, h, calcRect );
Rectangle tabCloseRect = getTabCloseBounds( tabIndex, x, y, w, h, calcRect );
closeIcon.paintIcon( tabCloseButton, g, tabCloseRect.x, tabCloseRect.y );
}

Expand Down Expand Up @@ -921,19 +921,24 @@ protected Rectangle getTabBounds( int tabIndex, Rectangle dest ) {
return super.getTabBounds( tabIndex, dest );
}

protected Rectangle getTabCloseBounds( int x, int y, int w, int h, Rectangle dest ) {
dest.width = closeIcon.getIconWidth();
dest.height = closeIcon.getIconHeight();
int xoffset = (h - dest.width) / 2;
int yoffset = (h - dest.height) / 2;
dest.x = isLeftToRight() ? (x + w - xoffset - dest.width) : (x + xoffset);
dest.y = y + yoffset;
protected Rectangle getTabCloseBounds( int tabIndex, int x, int y, int w, int h, Rectangle dest ) {
int iconWidth = closeIcon.getIconWidth();
int iconHeight = closeIcon.getIconHeight();
Insets tabInsets = getTabInsets( tabPane.getTabPlacement(), tabIndex );

// use one-third of right/left tab insets as gap between tab text and close button
dest.x = isLeftToRight()
? (x + w - (tabInsets.right / 3 * 2) - iconWidth)
: (x + (tabInsets.left / 3 * 2));
dest.y = y + (h - iconHeight) / 2;
dest.width = iconWidth;
dest.height = iconHeight;
return dest;
}

protected Rectangle getTabCloseHitArea( int tabIndex ) {
Rectangle tabRect = getTabBounds( tabPane, tabIndex );
Rectangle tabCloseRect = getTabCloseBounds( tabRect.x, tabRect.y, tabRect.width, tabRect.height, calcRect );
Rectangle tabCloseRect = getTabCloseBounds( tabIndex, tabRect.x, tabRect.y, tabRect.width, tabRect.height, calcRect );
return new Rectangle( tabCloseRect.x, tabRect.y, tabCloseRect.width, tabRect.height );
}

Expand Down

0 comments on commit c8d280f

Please sign in to comment.