Substance client properties

View all API methods.

View all client properties.


Client property name

SubstanceLookAndFeel.PASSWORD_ECHO_PER_CHAR

Description

Client property name for specifying the number of echo characters for each password character. The value should be an instance of Integer, otherwise will be ignored. This property can be set either on a specific JPasswordField or globally on UIManager.


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.pushingpixels.substance.api.SubstanceLookAndFeel;
import org.pushingpixels.substance.api.skin.BusinessBlackSteelSkin;

/**
 * Test application that shows the use of the
 {@link SubstanceLookAndFeel#PASSWORD_ECHO_PER_CHAR} client property.
 
 @author Kirill Grouchnikov
 @see SubstanceLookAndFeel#PASSWORD_ECHO_PER_CHAR
 */
public class PasswordEchoPerChar extends JFrame {
  /**
   * Creates the main frame for <code>this</code> sample.
   */
  public PasswordEchoPerChar() {
    super("Password echo per char");

    this.setLayout(new BorderLayout());
    final JPanel panel = new JPanel(new FlowLayout());
    this.add(panel, BorderLayout.CENTER);

    final JPasswordField jpf = new JPasswordField("sample");
    jpf.setColumns(20);
    panel.add(jpf);

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    final JSpinner countSpinner = new JSpinner();
    SpinnerNumberModel model = new SpinnerNumberModel(1151);
    countSpinner.setModel(model);
    countSpinner.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent e) {
        // set the amount of echo per character based on the current
        // value in the spinner
        jpf.putClientProperty(
            SubstanceLookAndFeel.PASSWORD_ECHO_PER_CHAR,
            countSpinner.getValue());
        jpf.repaint();
      }
    });

    controls.add(new JLabel("Echo per char"));
    controls.add(countSpinner);
    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.
   */
  public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        SubstanceLookAndFeel.setSkin(new BusinessBlackSteelSkin());
        new PasswordEchoPerChar().setVisible(true);
      }
    });
  }
}

The screenshot below shows application frame with password field that has the default setting of 1 echo character (this property is not set):

The screenshot below shows application frame with password field with this property set to 2 echo characters: