Substance client properties

View all API methods.

View all client properties.


Client property name

SubstanceLookAndFeel.TABBED_PANE_TEXT_ALIGNMENT_KIND

Description

Client property name for specifying the text alignment kind for on SwingConstants.LEFT and SwingConstants.RIGHT tab placements. This property can be specified either on a single JTabbedPane or on UIManager. The value should be one of SubstanceConstants.TabTextAlignmentKind enum. By default, the text alignment is SubstanceConstants.TabTextAlignmentKind.DEFAULT (centered).


See also


Sample code

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.utils.SubstanceConstants.TabTextAlignmentKind;

import test.Check;

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

    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());
    // set tabs to show on left
    jtp.setTabPlacement(JTabbedPane.LEFT);

    this.add(jtp, BorderLayout.CENTER);

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));

    final JCheckBox isOnLeft = new JCheckBox("Is on left");
    isOnLeft.setSelected(jtp.getTabPlacement() == JTabbedPane.LEFT);
    isOnLeft.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        // based on the checkbox selection, set tab placement to
        // either left or right
        jtp.setTabPlacement(isOnLeft.isSelected() ? JTabbedPane.LEFT
            : JTabbedPane.RIGHT);
        jtp.revalidate();
        jtp.repaint();
      }
    });

    controls.add(isOnLeft);

    final JComboBox alignmentCombo = new JComboBox(new Object[] {
        TabTextAlignmentKind.DEFAULT, TabTextAlignmentKind.ALWAYS_LEFT,
        TabTextAlignmentKind.ALWAYS_RIGHT,
        TabTextAlignmentKind.FOLLOW_PLACEMENT,
        TabTextAlignmentKind.FOLLOW_ORIENTATION });
    alignmentCombo.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        TabTextAlignmentKind alignment = (TabTextAlignmentKindalignmentCombo
            .getSelectedItem();
        // based on the combo selection, set the text alignment kind
        jtp.putClientProperty(
            SubstanceLookAndFeel.TABBED_PANE_TEXT_ALIGNMENT_KIND,
            alignment);
        jtp.revalidate();
        jtp.repaint();
      }
    });

    controls.add(new JLabel("Text alignment"));
    controls.add(alignmentCombo);
    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 TabbedPaneTextAlignmentKind().setVisible(true);
      }
    });
  }
}

The screenshot below shows tabbed pane with left placement and default (centered) text alignment - this property is not specified:

The screenshot below shows tabbed pane with left placement and SubstanceConstants.TabTextAlignmentKind.ALWAYS_RIGHT text alignment:

The screenshot below shows tabbed pane with right placement and SubstanceConstants.TabTextAlignmentKind.FOLLOW_PLACEMENT text alignment: