TabbedPane: support hiding separator between tabs and content area via client property

This commit is contained in:
Karl Tauber
2020-09-24 21:27:57 +02:00
parent d83c3689d0
commit fd63a1b7c2
7 changed files with 136 additions and 60 deletions

View File

@@ -17,10 +17,12 @@
package com.formdev.flatlaf.testing;
import static com.formdev.flatlaf.FlatClientProperties.TABBED_PANE_HAS_FULL_BORDER;
import static com.formdev.flatlaf.FlatClientProperties.TABBED_PANE_SHOW_CONTENT_SEPARATOR;
import static com.formdev.flatlaf.FlatClientProperties.TABBED_PANE_SHOW_TAB_SEPARATORS;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import com.formdev.flatlaf.util.ScaledImageIcon;
import com.jgoodies.forms.layout.*;
import net.miginfocom.swing.*;
@@ -65,18 +67,24 @@ public class FlatContainerTest
private void showTabSeparatorsChanged() {
Boolean showTabSeparators = showTabSeparatorsCheckBox.isSelected() ? true : null;
tabbedPane1.putClientProperty( TABBED_PANE_SHOW_TAB_SEPARATORS, showTabSeparators );
tabbedPane2.putClientProperty( TABBED_PANE_SHOW_TAB_SEPARATORS, showTabSeparators );
tabbedPane3.putClientProperty( TABBED_PANE_SHOW_TAB_SEPARATORS, showTabSeparators );
tabbedPane4.putClientProperty( TABBED_PANE_SHOW_TAB_SEPARATORS, showTabSeparators );
putTabbedPanesClientProperty( TABBED_PANE_SHOW_TAB_SEPARATORS, showTabSeparators );
}
private void hideContentSeparatorChanged() {
Boolean showContentSeparator = hideContentSeparatorCheckBox.isSelected() ? false : null;
putTabbedPanesClientProperty( TABBED_PANE_SHOW_CONTENT_SEPARATOR, showContentSeparator );
}
private void hasFullBorderChanged() {
Boolean hasFullBorder = hasFullBorderCheckBox.isSelected() ? true : null;
tabbedPane1.putClientProperty( TABBED_PANE_HAS_FULL_BORDER, hasFullBorder );
tabbedPane2.putClientProperty( TABBED_PANE_HAS_FULL_BORDER, hasFullBorder );
tabbedPane3.putClientProperty( TABBED_PANE_HAS_FULL_BORDER, hasFullBorder );
tabbedPane4.putClientProperty( TABBED_PANE_HAS_FULL_BORDER, hasFullBorder );
putTabbedPanesClientProperty( TABBED_PANE_HAS_FULL_BORDER, hasFullBorder );
}
private void putTabbedPanesClientProperty( String key, Object value ) {
tabbedPane1.putClientProperty( key, value );
tabbedPane2.putClientProperty( key, value );
tabbedPane3.putClientProperty( key, value );
tabbedPane4.putClientProperty( key, value );
}
private void moreTabsChanged() {
@@ -98,7 +106,7 @@ public class FlatContainerTest
addTab( tabbedPane, "Tab 8", "tab content 8" );
} else {
int tabCount = tabbedPane.getTabCount();
if( tabCount > 3 ) {
if( tabCount > 4 ) {
for( int i = 0; i < 5; i++ )
tabbedPane.removeTabAt( tabbedPane.getTabCount() - 1 );
}
@@ -115,6 +123,8 @@ public class FlatContainerTest
addTab( tabbedPane, "Disabled", "tab content 3" );
tabbedPane.setEnabledAt( 2, false );
tabbedPane.addTab( "Tab 4", new JLabel( "non-opaque content", SwingConstants.CENTER ) );
}
}
@@ -146,7 +156,7 @@ public class FlatContainerTest
Object iconSize = tabIconSizeSpinner.getValue();
Icon icon = showTabIcons
? new ImageIcon( getClass().getResource( "/com/formdev/flatlaf/testing/test" + iconSize + ".png" ) )
? new ScaledImageIcon( new ImageIcon( getClass().getResource( "/com/formdev/flatlaf/testing/test" + iconSize + ".png" ) ) )
: null;
tabbedPane.setIconAt( 0, icon );
tabbedPane.setIconAt( 1, icon );
@@ -174,6 +184,7 @@ public class FlatContainerTest
moreTabsCheckBox = new JCheckBox();
tabScrollCheckBox = new JCheckBox();
showTabSeparatorsCheckBox = new JCheckBox();
hideContentSeparatorCheckBox = new JCheckBox();
hasFullBorderCheckBox = new JCheckBox();
tabIconsCheckBox = new JCheckBox();
tabIconSizeSpinner = new JSpinner();
@@ -285,6 +296,7 @@ public class FlatContainerTest
"[]" +
"[]" +
"[]" +
"[fill]" +
"[]" +
"[fill]" +
"[fill]",
@@ -308,21 +320,26 @@ public class FlatContainerTest
showTabSeparatorsCheckBox.addActionListener(e -> showTabSeparatorsChanged());
panel14.add(showTabSeparatorsCheckBox, "cell 2 0");
//---- hideContentSeparatorCheckBox ----
hideContentSeparatorCheckBox.setText("Hide content separator");
hideContentSeparatorCheckBox.addActionListener(e -> hideContentSeparatorChanged());
panel14.add(hideContentSeparatorCheckBox, "cell 3 0");
//---- hasFullBorderCheckBox ----
hasFullBorderCheckBox.setText("Show content border");
hasFullBorderCheckBox.addActionListener(e -> hasFullBorderChanged());
panel14.add(hasFullBorderCheckBox, "cell 3 0,alignx left,growx 0");
panel14.add(hasFullBorderCheckBox, "cell 4 0,alignx left,growx 0");
//---- tabIconsCheckBox ----
tabIconsCheckBox.setText("Tab icons");
tabIconsCheckBox.addActionListener(e -> tabIconsChanged());
panel14.add(tabIconsCheckBox, "cell 4 0");
panel14.add(tabIconsCheckBox, "cell 5 0");
//---- tabIconSizeSpinner ----
tabIconSizeSpinner.setModel(new SpinnerListModel(new String[] {"16", "24", "32", "48", "64"}));
tabIconSizeSpinner.setEnabled(false);
tabIconSizeSpinner.addChangeListener(e -> tabIconsChanged());
panel14.add(tabIconSizeSpinner, "cell 5 0");
panel14.add(tabIconSizeSpinner, "cell 6 0");
}
panel9.add(panel14, cc.xywh(1, 11, 3, 1));
}
@@ -338,6 +355,7 @@ public class FlatContainerTest
private JCheckBox moreTabsCheckBox;
private JCheckBox tabScrollCheckBox;
private JCheckBox showTabSeparatorsCheckBox;
private JCheckBox hideContentSeparatorCheckBox;
private JCheckBox hasFullBorderCheckBox;
private JCheckBox tabIconsCheckBox;
private JSpinner tabIconSizeSpinner;

View File

@@ -131,7 +131,7 @@ new FormModel {
} )
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "insets 0,hidemode 3"
"$columnConstraints": "[][][][][fill][fill]"
"$columnConstraints": "[][][][fill][][fill][fill]"
"$rowConstraints": "[center]"
} ) {
name: "panel14"
@@ -168,6 +168,16 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 0"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "hideContentSeparatorCheckBox"
"text": "Hide content separator"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "hideContentSeparatorChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 3 0"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "hasFullBorderCheckBox"
"text": "Show content border"
@@ -176,7 +186,7 @@ new FormModel {
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "hasFullBorderChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 3 0,alignx left,growx 0"
"value": "cell 4 0,alignx left,growx 0"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "tabIconsCheckBox"
@@ -186,7 +196,7 @@ new FormModel {
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "tabIconsChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 4 0"
"value": "cell 5 0"
} )
add( new FormComponent( "javax.swing.JSpinner" ) {
name: "tabIconSizeSpinner"
@@ -205,7 +215,7 @@ new FormModel {
}
addEvent( new FormEvent( "javax.swing.event.ChangeListener", "stateChanged", "tabIconsChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 0"
"value": "cell 6 0"
} )
}, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) {
"gridY": 11
@@ -216,7 +226,7 @@ new FormModel {
} )
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 )
"size": new java.awt.Dimension( 625, 515 )
"size": new java.awt.Dimension( 810, 515 )
} )
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "hidemode 3,align center center"