Substance client properties

View all API methods.

View all client properties.


Client property name

SubstanceLookAndFeel.SCROLLBAR_GRIP_PAINTER

Description

Property name for specifying custom grip handles painted on scroll bars of scroll panes. The value should be an instance of ScrollThumbGripPainter interface. The CoreScrollThumbGripPainters is the factory class for available core implementations.


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.scroll.CoreScrollThumbGripPainters;

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

    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(800250));
    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));
    final JCheckBox hasOverlay = new JCheckBox(
        "scrollthumbs have custom grip painter");
    hasOverlay.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            // based on the checkbox selection, set custom grip
            // painter on the scroll pane
            scrollPane
                .putClientProperty(
                    SubstanceLookAndFeel.SCROLLBAR_GRIP_PAINTER,
                    hasOverlay.isSelected() new CoreScrollThumbGripPainters.DragBumpsScrollThumbGripPainter()
                        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 ScrollBarGripPainter().setVisible(true);
      }
    });
  }
}

The screenshot below shows application frame with scroll pane in default state - doesn't have this property installed:

The screenshot below shows application frame with scroll pane that has this property installed to a core implementation