TabbedPane: support horizontal alignment of tab title and icon

This commit is contained in:
Karl Tauber
2020-11-03 20:13:14 +01:00
parent 3a784375d0
commit a7e2a10403
12 changed files with 352 additions and 95 deletions

View File

@@ -937,6 +937,7 @@ TabbedPane.selectedTabPadInsets 0,0,0,0 javax.swing.plaf.InsetsUIResource [UI
TabbedPane.selectionFollowsFocus true
TabbedPane.shadow #3c3f41 javax.swing.plaf.ColorUIResource [UI]
TabbedPane.showTabSeparators false
TabbedPane.tabAlignment center
TabbedPane.tabAreaAlignment leading
TabbedPane.tabAreaInsets 0,0,0,0 javax.swing.plaf.InsetsUIResource [UI]
TabbedPane.tabHeight 32

View File

@@ -942,6 +942,7 @@ TabbedPane.selectedTabPadInsets 0,0,0,0 javax.swing.plaf.InsetsUIResource [UI
TabbedPane.selectionFollowsFocus true
TabbedPane.shadow #f2f2f2 javax.swing.plaf.ColorUIResource [UI]
TabbedPane.showTabSeparators false
TabbedPane.tabAlignment center
TabbedPane.tabAreaAlignment leading
TabbedPane.tabAreaInsets 0,0,0,0 javax.swing.plaf.InsetsUIResource [UI]
TabbedPane.tabHeight 32

View File

@@ -932,6 +932,7 @@ TabbedPane.selectedTabPadInsets 0,0,0,0 javax.swing.plaf.InsetsUIResource [UI
TabbedPane.selectionFollowsFocus true
TabbedPane.shadow #ccffcc javax.swing.plaf.ColorUIResource [UI]
TabbedPane.showTabSeparators false
TabbedPane.tabAlignment center
TabbedPane.tabAreaAlignment leading
TabbedPane.tabAreaInsets 0,0,0,0 javax.swing.plaf.InsetsUIResource [UI]
TabbedPane.tabHeight 32

View File

@@ -276,6 +276,17 @@ public class FlatContainerTest
putTabbedPanesClientProperty( TABBED_PANE_TAB_AREA_ALIGNMENT, value );
}
private void tabAlignmentChanged() {
String value = (String) tabAlignmentField.getSelectedItem();
Integer tabAlignment = null;
switch( value ) {
case "center": tabAlignment = SwingConstants.CENTER; break;
case "leading": tabAlignment = SwingConstants.LEADING; break;
case "trailing": tabAlignment = SwingConstants.TRAILING; break;
}
putTabbedPanesClientProperty( TABBED_PANE_TAB_ALIGNMENT, tabAlignment );
}
private void tabWidthModeChanged() {
String value = (String) tabWidthModeField.getSelectedItem();
if( "default".equals( value ) )
@@ -416,6 +427,7 @@ public class FlatContainerTest
iconPlacementField = new JComboBox<>();
JLabel tabAreaAlignmentLabel = new JLabel();
tabAreaAlignmentField = new JComboBox<>();
tabAlignmentField = new JComboBox<>();
JLabel tabWidthModeLabel = new JLabel();
tabWidthModeField = new JComboBox<>();
tabsClosableCheckBox = new JCheckBox();
@@ -637,7 +649,7 @@ public class FlatContainerTest
tabbedPaneControlPanel.add(iconPlacementField, "cell 2 2");
//---- tabAreaAlignmentLabel ----
tabAreaAlignmentLabel.setText("Tab area alignment:");
tabAreaAlignmentLabel.setText("Tab area/title alignment:");
tabbedPaneControlPanel.add(tabAreaAlignmentLabel, "cell 0 3");
//---- tabAreaAlignmentField ----
@@ -651,6 +663,16 @@ public class FlatContainerTest
tabAreaAlignmentField.addActionListener(e -> tabAreaAlignmentChanged());
tabbedPaneControlPanel.add(tabAreaAlignmentField, "cell 1 3");
//---- tabAlignmentField ----
tabAlignmentField.setModel(new DefaultComboBoxModel<>(new String[] {
"default",
"leading",
"trailing",
"center"
}));
tabAlignmentField.addActionListener(e -> tabAlignmentChanged());
tabbedPaneControlPanel.add(tabAlignmentField, "cell 1 3");
//---- tabWidthModeLabel ----
tabWidthModeLabel.setText("Tab width mode:");
tabbedPaneControlPanel.add(tabWidthModeLabel, "cell 2 3");
@@ -760,6 +782,7 @@ public class FlatContainerTest
private JSpinner tabIconSizeSpinner;
private JComboBox<String> iconPlacementField;
private JComboBox<String> tabAreaAlignmentField;
private JComboBox<String> tabAlignmentField;
private JComboBox<String> tabWidthModeField;
private JCheckBox tabsClosableCheckBox;
private JCheckBox customBorderCheckBox;

View File

@@ -300,7 +300,7 @@ new FormModel {
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "tabAreaAlignmentLabel"
"text": "Tab area alignment:"
"text": "Tab area/title alignment:"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 3"
} )
@@ -322,6 +322,23 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 3"
} )
add( new FormComponent( "javax.swing.JComboBox" ) {
name: "tabAlignmentField"
"model": new javax.swing.DefaultComboBoxModel {
selectedItem: "default"
addElement( "default" )
addElement( "leading" )
addElement( "trailing" )
addElement( "center" )
}
auxiliary() {
"JavaCodeGenerator.variableLocal": false
"JavaCodeGenerator.typeParameters": "String"
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "tabAlignmentChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 3"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "tabWidthModeLabel"
"text": "Tab width mode:"