Substance API

View all API methods.

View all client properties.


API method

public static String getCurrentGradientPainterName()

Description

Returns the current gradient painter name.

Returns:

  • The current gradient painter name.

See also


Sample code

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.*;
import java.util.Vector;

import javax.swing.*;

import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.painter.GradientPainterInfo;

/**
 * Test application that shows the use of the
 {@link SubstanceLookAndFeel#getCurrentGradientPainterName()} API.
 
 @author Kirill Grouchnikov
 @see SubstanceLookAndFeel#getCurrentGradientPainterName()
 */
public class GetCurrentGradientPainterName extends JFrame {
  /**
   * Creates the main frame for <code>this</code> sample.
   */
  public GetCurrentGradientPainterName() {
    super("Get current gradient painter name");

    this.setLayout(new BorderLayout());

    JPanel panel = new JPanel(new FlowLayout());

    // Get all gradient painter display names and set the vector as a model
    // for combobox.
    final JComboBox cb = new JComboBox(new Vector<String>(
        SubstanceLookAndFeel.getAllGradientPainters().keySet()));
    cb
        .setSelectedItem(SubstanceLookAndFeel
            .getCurrentGradientPainterName());

    cb.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent evt) {
        // Get the affected item
        final Object item = evt.getItem();

        if (evt.getStateChange() == ItemEvent.SELECTED) {
          SwingUtilities.invokeLater(new Runnable() {
            public void run() {
              try {
                // Get the gradient painter info object based on
                // the selected gradient painter display name
                GradientPainterInfo painterInfo = SubstanceLookAndFeel
                    .getAllGradientPainters().get(
                        (Stringitem);
                // Set the global gradient painter based on the
                // gradient painter class name.
                SubstanceLookAndFeel
                    .setCurrentGradientPainter(painterInfo
                        .getClassName());
                SwingUtilities
                    .updateComponentTreeUI(GetCurrentGradientPainterName.this);
              catch (Exception exc) {
              }
            };
          });
        }
      }
    });

    panel.add(new JLabel("All gradient painters:"));
    panel.add(cb);

    this.add(panel, BorderLayout.CENTER);

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

    JButton getGradientPainterName = new JButton(
        "Get current gradient painter name");
    getGradientPainterName.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        JOptionPane.showMessageDialog(
            GetCurrentGradientPainterName.this,
            "Current gradient painter name is "
                + SubstanceLookAndFeel
                    .getCurrentGradientPainterName());
      }
    });

    controls.add(getGradientPainterName);
    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);
    JDialog.setDefaultLookAndFeelDecorated(true);
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        new GetCurrentGradientPainterName().setVisible(true);
      }
    });
  }
}

The screenshot below shows the result of calling this API on the default (standard) gradient painter. Note the display name and the default fill:

The screenshot below shows the result of calling this API after the specular gradient painter has been selected in the combobox. Note the display name and the specular gradient: