Substance client properties

View all API methods.

View all client properties.


Client property name

SubstanceLookAndFeel.TABBED_PANE_CLOSE_BUTTONS_SIZE

Description

Client property name for specifying the size of the close button on tabbed panes. This property can be specified on a single tab component, on a JTabbedPane itself (will hold for all tab components that don't define this property) or on UIManager. The value should be either Boolean.TRUE or Boolean.FALSE. The default value is SubstanceTabbedPaneUI.TAB_DEFAULT_BUTTON_DIMENSION. Note that this setting is relevant only for tabs with close buttons (see SubstanceLookAndFeel.TABBED_PANE_CLOSE_BUTTONS_PROPERTY.


See also


Sample code

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.jvnet.substance.SubstanceLookAndFeel;

import test.Check;

/**
 * Test application that shows the use of the
 {@link SubstanceLookAndFeel#TABBED_PANE_CLOSE_BUTTONS_SIZE} client property.
 
 @author Kirill Grouchnikov
 @see SubstanceLookAndFeel#TABBED_PANE_CLOSE_BUTTONS_SIZE
 */
public class TabbedPaneCloseButtonsSize extends JFrame {
  /**
   * Creates the main frame for <code>this</code> sample.
   */
  public TabbedPaneCloseButtonsSize() {
    super("Tabbed pane close buttons size");

    this.setLayout(new BorderLayout());

    // create tabbed pane with a few tabs
    final JTabbedPane jtp = new JTabbedPane();
    jtp.addTab("First", Check.getIcon("flag_mexico")new JPanel());
    jtp.addTab("Second", Check.getIcon("flag_sweden")new JPanel());
    jtp.addTab("Third", Check.getIcon("flag_hong_kong")new JPanel());
    // mark the tabbed pane to have close buttons on all the tabs
    jtp.putClientProperty(
        SubstanceLookAndFeel.TABBED_PANE_CLOSE_BUTTONS_PROPERTY,
        Boolean.TRUE);

    this.add(jtp, BorderLayout.CENTER);

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    final JSpinner sizeSpinner = new JSpinner();
    SpinnerNumberModel model = new SpinnerNumberModel(118171);
    sizeSpinner.setModel(model);
    sizeSpinner.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent e) {
        // set the close buttons size based on the current value
        // in the spinner
        jtp.putClientProperty(
            SubstanceLookAndFeel.TABBED_PANE_CLOSE_BUTTONS_SIZE,
            sizeSpinner.getValue());
        jtp.revalidate();
        jtp.repaint();
      }
    });

    controls.add(new JLabel("Close button size"));
    controls.add(sizeSpinner);
    this.add(controls, BorderLayout.SOUTH);

    this.setSize(400200);
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }

  /**
   * The main method for <code>this</code> sample. The arguments are
   * ignored.
   
   @param args
   *            Ignored.
   @throws Exception
   *             If some exception occured. Note that there is no special
   *             treatment of exception conditions in <code>this</code>
   *             sample code.
   */
  public static void main(String[] argsthrows Exception {
    UIManager.setLookAndFeel(new SubstanceLookAndFeel());
    JFrame.setDefaultLookAndFeelDecorated(true);
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        new TabbedPaneCloseButtonsSize().setVisible(true);
      }
    });
  }
}

The screenshot below shows tabbed pane with close buttons of default size (11 points) - this property is not set:

The screenshot below shows tabbed pane with close buttons of custom size - this property is set to 13. Note how tabs grow to accomodate for extra width:

The screenshot below shows tabbed pane with close buttons of custom size - this property is set to 9. Note how tabs shrink to compensate for smaller width: