Substance client properties

View all API methods.

View all client properties.


Client property name

SubstanceLookAndFeel.BACKGROUND_COMPOSITE

Description

Client property name for specifying the background composite for various translucency effects. This property can be set either as a client property on a specific control or as a global setting on UIManager. The value should be an instance of ControlBackgroundComposite. Available core implementations include AlphaControlBackgroundComposite, DefaultControlBackgroundComposite and DecayControlBackgroundComposite.

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.painter.AlphaControlBackgroundComposite;

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

    this.setLayout(new BorderLayout());

    // Create panel with custom painting logic - simple
    // diagonal fill.
    JPanel samplePanel = new JPanel() {
      @Override
      protected void paintComponent(Graphics g) {
        Graphics2D graphics = (Graphics2Dg.create();
        graphics
            .setPaint(new GradientPaint(00new Color(100100,
                255), getWidth(), getHeight()new Color(255,
                100100)));
        graphics.fillRect(00, getWidth(), getHeight());
        graphics.dispose();
      }
    };
    samplePanel.setPreferredSize(new Dimension(800400));
    samplePanel.setSize(this.getPreferredSize());
    samplePanel.setMinimumSize(this.getPreferredSize());

    final JScrollPane scrollPane = new JScrollPane(samplePanel);

    this.add(scrollPane, BorderLayout.CENTER);

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    JButton set30_50_Composite = new JButton("Set 30-50");
    set30_50_Composite.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            scrollPane
                .putClientProperty(
                    SubstanceLookAndFeel.BACKGROUND_COMPOSITE,
                    new AlphaControlBackgroundComposite(
                        0.3f0.5f));
            repaint();
          }
        });
      }
    });
    controls.add(set30_50_Composite);

    JButton set50_70_Composite = new JButton("Set 50-70");
    set50_70_Composite.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            scrollPane
                .putClientProperty(
                    SubstanceLookAndFeel.BACKGROUND_COMPOSITE,
                    new AlphaControlBackgroundComposite(
                        0.5f0.5f));
            repaint();
          }
        });
      }
    });
    controls.add(set50_70_Composite);
    JButton set50_100_Composite = new JButton("Set 50-100");
    set50_100_Composite.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            scrollPane.putClientProperty(
                SubstanceLookAndFeel.BACKGROUND_COMPOSITE,
                new AlphaControlBackgroundComposite(0.5f));
            repaint();
          }
        });
      }
    });
    controls.add(set50_100_Composite);
    JButton set70_70_Composite = new JButton("Set 70-70");
    set70_70_Composite.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            scrollPane
                .putClientProperty(
                    SubstanceLookAndFeel.BACKGROUND_COMPOSITE,
                    new AlphaControlBackgroundComposite(
                        0.7f0.7f));
            repaint();
          }
        });
      }
    });
    controls.add(set70_70_Composite);

    final JCheckBox hasOverlay = new JCheckBox("has overlay");
    hasOverlay.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            scrollPane.putClientProperty(
                SubstanceLookAndFeel.OVERLAY_PROPERTY,
                hasOverlay.isSelected() ? Boolean.TRUE : null);
            repaint();
          }
        });
      }
    });
    controls.add(hasOverlay);

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

Note - the screenshots below are taken after the "has overlay" checkbox is selected. This sets the OVERLAY_PROPERTY on the scroll pane, making the contents of the viewport partially visible through the scrollbars.

The initial state of the application (no custom background composite set on the scroll pane). Note that even though the overlay property is set, the viewport contents don't show through since the default composite is 100% opaque.

AlphaControlBackgroundComposite set with 50% opacity in default state and 100% opacity in rollover / active state. Note that both scrollbars are in default state, and the viewport contents show through (50% opacity).

The same background composite set and the mouse hovers over the right (increase) arrow button of the horizontal scrollbar. Note that the scrollbar and the button are in active state and have 100% opacity (viewport is obscured).