Substance API

View all API methods.

View all client properties.


API method

public static boolean setCurrentGradientPainter(
      String gradientPainterClassName)

Description

Sets new gradient painter.

Parameters:

  • gradientPainterClassName - Gradient painter class name (full qualified).

Returns:

  • The status of the gradient painter change.

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;

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

    this.setLayout(new BorderLayout());

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    final JButton changeGradientPainter = new JButton(
        "Change gradient painter");
    changeGradientPainter.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            changeGradientPainter.setEnabled(false);
            // set new gradient painter by class name
            SubstanceLookAndFeel
                .setCurrentGradientPainter("org.jvnet.substance.painter.SpecularGradientPainter");
            repaint();
          }
        });
      }
    });
    controls.add(changeGradientPainter);

    JButton getGradientPainterName = new JButton(
        "Get current gradient painter name");
    getGradientPainterName.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        JOptionPane.showMessageDialog(
            SetCurrentGradientPainter_ClassName.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 SetCurrentGradientPainter_ClassName().setVisible(true);
      }
    });
  }
}

The screenshot below shows application frame under default gradient painter (Standard). Note the fill (mouse is over the left button):

The screenshot below shows the result of calling this API with org.jvnet.substance.painter.SpecularGradientPainter. Note the specular fill (mouse is over the right button):