TabbedPane: support left, right, top and bottom tab icon placement

This commit is contained in:
Karl Tauber
2020-10-30 01:47:14 +01:00
parent df13b338b2
commit e2a297fa40
5 changed files with 124 additions and 16 deletions

View File

@@ -176,6 +176,17 @@ public class FlatContainerTest
tabbedPane.setIconAt( i, icon );
}
private void iconPlacementChanged() {
Object iconPlacement = null;
switch( (String) iconPlacementField.getSelectedItem() ) {
case "leading": iconPlacement = SwingConstants.LEADING; break;
case "trailing": iconPlacement = SwingConstants.TRAILING; break;
case "top": iconPlacement = SwingConstants.TOP; break;
case "bottom": iconPlacement = SwingConstants.BOTTOM; break;
}
putTabbedPanesClientProperty( TABBED_PANE_TAB_ICON_PLACEMENT, iconPlacement );
}
private void customBorderChanged() {
Border border = customBorderCheckBox.isSelected()
? new MatteBorder( 10, 20, 25, 35, Color.green )
@@ -390,6 +401,7 @@ public class FlatContainerTest
tabPlacementField = new JComboBox<>();
tabIconsCheckBox = new JCheckBox();
tabIconSizeSpinner = new JSpinner();
iconPlacementField = new JComboBox<>();
JLabel tabAreaAlignmentLabel = new JLabel();
tabAreaAlignmentField = new JComboBox<>();
JLabel tabWidthModeLabel = new JLabel();
@@ -592,6 +604,16 @@ public class FlatContainerTest
tabIconSizeSpinner.addChangeListener(e -> tabIconsChanged());
tabbedPaneControlPanel.add(tabIconSizeSpinner, "cell 2 2");
//---- iconPlacementField ----
iconPlacementField.setModel(new DefaultComboBoxModel<>(new String[] {
"leading",
"trailing",
"top",
"bottom"
}));
iconPlacementField.addActionListener(e -> iconPlacementChanged());
tabbedPaneControlPanel.add(iconPlacementField, "cell 2 2");
//---- tabAreaAlignmentLabel ----
tabAreaAlignmentLabel.setText("Tab area alignment:");
tabbedPaneControlPanel.add(tabAreaAlignmentLabel, "cell 0 3");
@@ -710,6 +732,7 @@ public class FlatContainerTest
private JComboBox<String> tabPlacementField;
private JCheckBox tabIconsCheckBox;
private JSpinner tabIconSizeSpinner;
private JComboBox<String> iconPlacementField;
private JComboBox<String> tabAreaAlignmentField;
private JComboBox<String> tabWidthModeField;
private JCheckBox tabsClosableCheckBox;

View File

@@ -261,6 +261,23 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 2"
} )
add( new FormComponent( "javax.swing.JComboBox" ) {
name: "iconPlacementField"
"model": new javax.swing.DefaultComboBoxModel {
selectedItem: "leading"
addElement( "leading" )
addElement( "trailing" )
addElement( "top" )
addElement( "bottom" )
}
auxiliary() {
"JavaCodeGenerator.variableLocal": false
"JavaCodeGenerator.typeParameters": "String"
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "iconPlacementChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 2"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "tabAreaAlignmentLabel"
"text": "Tab area alignment:"