Substance client properties

View all API methods.

View all client properties.


Client property name

SubstanceLookAndFeel.OVERLAY_PROPERTY

Description

Client property name for specifying that a single control / all application controls have overlay functionality. 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 either Boolean.TRUE or Boolean.FALSE.


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#OVERLAY_PROPERTY} client property.
 
 @author Kirill Grouchnikov
 @see SubstanceLookAndFeel#OVERLAY_PROPERTY
 */
public class OverlayProperty extends JFrame {
  /**
   * Creates the main frame for <code>this</code> sample.
   */
  public OverlayProperty() {
    super("Overlay");

    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);
    // set background composite on the scroll pane, so that when the overlay
    // property is set, the viewport contents will show through the
    // scrollbars of the scroll pane
    scrollPane.putClientProperty(SubstanceLookAndFeel.BACKGROUND_COMPOSITE,
        new AlphaControlBackgroundComposite(0.3f0.5f));

    this.add(scrollPane, BorderLayout.CENTER);

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    final JCheckBox hasOverlay = new JCheckBox("scroll has overlay");
    hasOverlay.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            // based on the checkbox selection, set the overlay
            // property on the scroll pane
            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 OverlayProperty().setVisible(true);
      }
    });
  }
}

Note that the screenshots below show the application running under custom background composite that allows specifying custom opacity on the scrollbars.

The screenshot below shows scroll pane in default state (this property is not specified):

The screenshot below shows scroll pane with this property set to Boolean.TRUE: