mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 14:37:13 -06:00
TabbedPane: improved/fixed placement of tab close button on smaller tab insets or smaller tab height (PR #193)
This commit is contained in:
@@ -715,7 +715,7 @@ public class FlatTabbedPaneUI
|
|||||||
bm.setPressed( rollover && isPressedTabClose() );
|
bm.setPressed( rollover && isPressedTabClose() );
|
||||||
|
|
||||||
// paint tab close icon
|
// 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 );
|
closeIcon.paintIcon( tabCloseButton, g, tabCloseRect.x, tabCloseRect.y );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -921,19 +921,24 @@ public class FlatTabbedPaneUI
|
|||||||
return super.getTabBounds( tabIndex, dest );
|
return super.getTabBounds( tabIndex, dest );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Rectangle getTabCloseBounds( int x, int y, int w, int h, Rectangle dest ) {
|
protected Rectangle getTabCloseBounds( int tabIndex, int x, int y, int w, int h, Rectangle dest ) {
|
||||||
dest.width = closeIcon.getIconWidth();
|
int iconWidth = closeIcon.getIconWidth();
|
||||||
dest.height = closeIcon.getIconHeight();
|
int iconHeight = closeIcon.getIconHeight();
|
||||||
int xoffset = (h - dest.width) / 2;
|
Insets tabInsets = getTabInsets( tabPane.getTabPlacement(), tabIndex );
|
||||||
int yoffset = (h - dest.height) / 2;
|
|
||||||
dest.x = isLeftToRight() ? (x + w - xoffset - dest.width) : (x + xoffset);
|
// use one-third of right/left tab insets as gap between tab text and close button
|
||||||
dest.y = y + yoffset;
|
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;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Rectangle getTabCloseHitArea( int tabIndex ) {
|
protected Rectangle getTabCloseHitArea( int tabIndex ) {
|
||||||
Rectangle tabRect = getTabBounds( tabPane, 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 );
|
return new Rectangle( tabCloseRect.x, tabRect.y, tabCloseRect.width, tabRect.height );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user