Substance API

View all API methods.

View all client properties.


API method

public static ColorScheme getActiveColorScheme()

Description

Returns the current color scheme for components in active visual state.

Returns:

  • Current color scheme for components in active visual state.

See also


Sample code

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.color.ColorScheme;
import org.jvnet.substance.theme.*;

/**
 * Test application that shows the use of the
 {@link SubstanceLookAndFeel#getActiveColorScheme()} API.
 
 @author Kirill Grouchnikov
 @see SubstanceLookAndFeel#getActiveColorScheme()
 */
public class GetActiveColorScheme extends JFrame {
  /**
   * Creates the main frame for <code>this</code> sample.
   */
  public GetActiveColorScheme() {
    super("Get active color scheme");

    this.setLayout(new BorderLayout());

    final JPanel panel = new JPanel() {
      @Override
      protected void paintComponent(Graphics g) {
        int width = getWidth();
        int height = getHeight();

        // paint the panel with the colors of the current
        // active color scheme
        ColorScheme scheme = SubstanceLookAndFeel
            .getActiveColorScheme();
        Paint paint = new GradientPaint(00, scheme
            .getUltraLightColor(), width, height, scheme
            .getLightColor());
        Graphics2D g2 = (Graphics2Dg.create();
        g2.setPaint(paint);
        g2.fillRect(00, width, height);
        g2.dispose();
      }
    };
    this.add(panel, BorderLayout.CENTER);

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    final JButton setAqua = new JButton("Set Aqua");
    setAqua.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            // Set Aqua theme
            SubstanceLookAndFeel
                .setCurrentTheme(new SubstanceAquaTheme());
            SwingUtilities
                .updateComponentTreeUI(GetActiveColorScheme.this);
          }
        });
      }
    });
    controls.add(setAqua);

    final JButton setPink = new JButton("Set Pink");
    setPink.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            // Set Barby Pink theme
            SubstanceLookAndFeel
                .setCurrentTheme(new SubstanceBarbyPinkTheme());
            SwingUtilities
                .updateComponentTreeUI(GetActiveColorScheme.this);
          }
        });
      }
    });
    controls.add(setPink);

    this.add(controls, BorderLayout.SOUTH);

    // register theme change listener to repaint the panel on theme change
    SubstanceLookAndFeel
        .registerThemeChangeListener(new ThemeChangeListener() {
          public void themeChanged() {
            panel.repaint();
          }
        });

    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 GetActiveColorScheme().setVisible(true);
      }
    });
  }
}

The screenshot below shows application frame with main panel colored with the active color scheme of default theme (Aqua):

The screenshot below shows application frame with main panel colored with the active color scheme of the currently set theme (Barby Pink):