TabbedPane: support hiding tab area if it contains only one tab

This commit is contained in:
Karl Tauber
2020-11-28 11:21:46 +01:00
parent 21a12b8dd4
commit d0ffc4f979
5 changed files with 67 additions and 4 deletions

View File

@@ -219,7 +219,7 @@ public interface FlatClientProperties
*/
String MENU_BAR_EMBEDDED = "JRootPane.menuBarEmbedded";
//---- JScrollBar ---------------------------------------------------------
//---- JScrollBar / JScrollPane -------------------------------------------
/**
* Specifies whether the decrease/increase arrow buttons of a scrollbar are shown.
@@ -263,6 +263,14 @@ public interface FlatClientProperties
*/
String TABBED_PANE_HAS_FULL_BORDER = "JTabbedPane.hasFullBorder";
/**
* Specifies whether the tab area should be hidded if it contains only one tab.
* <p>
* <strong>Component</strong> {@link javax.swing.JTabbedPane}<br>
* <strong>Value type</strong> {@link java.lang.Boolean}
*/
String TABBED_PANE_HIDE_TAB_AREA_WITH_ONE_TAB = "JTabbedPane.hideTabAreaWithOneTab";
/**
* Specifies the minimum width of a tab.
* <p>

View File

@@ -693,6 +693,26 @@ public class FlatTabbedPaneUI
return Math.max( tabHeight, scale( clientPropertyInt( tabPane, TABBED_PANE_TAB_HEIGHT, this.tabHeight ) ) );
}
@Override
protected int calculateMaxTabWidth( int tabPlacement ) {
return hideTabArea() ? 0 : super.calculateMaxTabWidth( tabPlacement );
}
@Override
protected int calculateMaxTabHeight( int tabPlacement ) {
return hideTabArea() ? 0 : super.calculateMaxTabHeight( tabPlacement );
}
@Override
protected int calculateTabAreaWidth( int tabPlacement, int vertRunCount, int maxTabWidth ) {
return hideTabArea() ? 0 : super.calculateTabAreaWidth( tabPlacement, vertRunCount, maxTabWidth );
}
@Override
protected int calculateTabAreaHeight( int tabPlacement, int horizRunCount, int maxTabHeight ) {
return hideTabArea() ? 0 : super.calculateTabAreaHeight( tabPlacement, horizRunCount, maxTabHeight );
}
@Override
protected Insets getTabInsets( int tabPlacement, int tabIndex ) {
Object value = getTabClientProperty( tabIndex, TABBED_PANE_TAB_INSETS );
@@ -752,7 +772,7 @@ public class FlatTabbedPaneUI
*/
@Override
protected Insets getContentBorderInsets( int tabPlacement ) {
if( contentSeparatorHeight == 0 || !clientPropertyBoolean( tabPane, TABBED_PANE_SHOW_CONTENT_SEPARATOR, true ) )
if( hideTabArea() || contentSeparatorHeight == 0 || !clientPropertyBoolean( tabPane, TABBED_PANE_SHOW_CONTENT_SEPARATOR, true ) )
return new Insets( 0, 0, 0, 0 );
boolean hasFullBorder = clientPropertyBoolean( tabPane, TABBED_PANE_HAS_FULL_BORDER, this.hasFullBorder );
@@ -787,6 +807,9 @@ public class FlatTabbedPaneUI
@Override
public void paint( Graphics g, JComponent c ) {
if( hideTabArea() )
return;
ensureCurrentLayout();
int tabPlacement = tabPane.getTabPlacement();
@@ -1226,6 +1249,13 @@ public class FlatTabbedPaneUI
return UIManager.getBoolean( "ScrollPane.smoothScrolling" );
}
protected boolean hideTabArea() {
return tabPane.getTabCount() == 1 &&
leadingComponent == null &&
trailingComponent == null &&
clientPropertyBoolean( tabPane, TABBED_PANE_HIDE_TAB_AREA_WITH_ONE_TAB, false );
}
protected int getTabsPopupPolicy() {
Object value = tabPane.getClientProperty( TABBED_PANE_TABS_POPUP_POLICY );
@@ -2193,6 +2223,7 @@ public class FlatTabbedPaneUI
case TABBED_PANE_SHOW_TAB_SEPARATORS:
case TABBED_PANE_SHOW_CONTENT_SEPARATOR:
case TABBED_PANE_HAS_FULL_BORDER:
case TABBED_PANE_HIDE_TAB_AREA_WITH_ONE_TAB:
case TABBED_PANE_MINIMUM_TAB_WIDTH:
case TABBED_PANE_MAXIMUM_TAB_WIDTH:
case TABBED_PANE_TAB_HEIGHT: