TabbedPane: support equal and compact tab width modes

This commit is contained in:
Karl Tauber
2020-10-29 19:26:09 +01:00
parent 0374c65159
commit da9d7a0dee
5 changed files with 157 additions and 17 deletions

View File

@@ -172,10 +172,8 @@ public class FlatContainerTest
? new ScaledImageIcon( new ImageIcon( getClass().getResource( "/com/formdev/flatlaf/testing/test" + iconSize + ".png" ) ) )
: null;
int tabCount = tabbedPane.getTabCount();
if( tabCount > 0 )
tabbedPane.setIconAt( 0, icon );
if( tabCount > 1 )
tabbedPane.setIconAt( 1, icon );
for( int i = 0; i < tabCount; i++ )
tabbedPane.setIconAt( i, icon );
}
private void customBorderChanged() {
@@ -252,6 +250,13 @@ public class FlatContainerTest
putTabbedPanesClientProperty( TABBED_PANE_TAB_AREA_ALIGNMENT, value );
}
private void tabWidthModeChanged() {
String value = (String) tabWidthModeField.getSelectedItem();
if( "default".equals( value ) )
value = null;
putTabbedPanesClientProperty( TABBED_PANE_TAB_WIDTH_MODE, value );
}
private void tabBackForegroundChanged() {
tabBackForegroundChanged( tabbedPane1 );
tabBackForegroundChanged( tabbedPane2 );
@@ -387,6 +392,8 @@ public class FlatContainerTest
tabIconSizeSpinner = new JSpinner();
JLabel tabAreaAlignmentLabel = new JLabel();
tabAreaAlignmentField = new JComboBox<>();
JLabel tabWidthModeLabel = new JLabel();
tabWidthModeField = new JComboBox<>();
tabsClosableCheckBox = new JCheckBox();
customBorderCheckBox = new JCheckBox();
tabAreaInsetsCheckBox = new JCheckBox();
@@ -600,6 +607,20 @@ public class FlatContainerTest
tabAreaAlignmentField.addActionListener(e -> tabAreaAlignmentChanged());
tabbedPaneControlPanel.add(tabAreaAlignmentField, "cell 1 3");
//---- tabWidthModeLabel ----
tabWidthModeLabel.setText("Tab width mode:");
tabbedPaneControlPanel.add(tabWidthModeLabel, "cell 2 3");
//---- tabWidthModeField ----
tabWidthModeField.setModel(new DefaultComboBoxModel<>(new String[] {
"default",
"preferred",
"equal",
"compact"
}));
tabWidthModeField.addActionListener(e -> tabWidthModeChanged());
tabbedPaneControlPanel.add(tabWidthModeField, "cell 2 3");
//---- tabsClosableCheckBox ----
tabsClosableCheckBox.setText("Tabs closable");
tabsClosableCheckBox.addActionListener(e -> tabsClosableChanged());
@@ -690,6 +711,7 @@ public class FlatContainerTest
private JCheckBox tabIconsCheckBox;
private JSpinner tabIconSizeSpinner;
private JComboBox<String> tabAreaAlignmentField;
private JComboBox<String> tabWidthModeField;
private JCheckBox tabsClosableCheckBox;
private JCheckBox customBorderCheckBox;
private JCheckBox tabAreaInsetsCheckBox;

View File

@@ -285,6 +285,29 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 3"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "tabWidthModeLabel"
"text": "Tab width mode:"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 3"
} )
add( new FormComponent( "javax.swing.JComboBox" ) {
name: "tabWidthModeField"
"model": new javax.swing.DefaultComboBoxModel {
selectedItem: "default"
addElement( "default" )
addElement( "preferred" )
addElement( "equal" )
addElement( "compact" )
}
auxiliary() {
"JavaCodeGenerator.variableLocal": false
"JavaCodeGenerator.typeParameters": "String"
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "tabWidthModeChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 3"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "tabsClosableCheckBox"
"text": "Tabs closable"