Substance API

View all API methods.

View all client properties.


API method

public static boolean setCurrentWatermark(
      SubstanceWatermark currentWatermark)

Description

Sets new watermark.

Parameters:

  • currentWatermark - Watermark object.

Returns:

  • The status of the watermark 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;
import org.jvnet.substance.watermark.SubstanceBinaryWatermark;

/**
 * Test application that shows the use of the
 {@link SubstanceLookAndFeel#setCurrentWatermark(org.jvnet.substance.watermark.SubstanceWatermark)} API.
 
 @author Kirill Grouchnikov
 @see SubstanceLookAndFeel#setCurrentWatermark(org.jvnet.substance.watermark.SubstanceWatermark)
 */
public class SetCurrentWatermark_Instance extends JFrame {
  /**
   * Creates the main frame for <code>this</code> sample.
   */
  public SetCurrentWatermark_Instance() {
    super("Set current watermark");

    this.setLayout(new BorderLayout());

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    final JButton changeWatermark = new JButton("Change watermark");
    changeWatermark.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            changeWatermark.setEnabled(false);
            // set new watermark by instance
            SubstanceLookAndFeel
                .setCurrentWatermark(new SubstanceBinaryWatermark());
            repaint();
          }
        });
      }
    });
    controls.add(changeWatermark);

    JButton getWatermarkName = new JButton("Get current watermark name");
    getWatermarkName.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        JOptionPane.showMessageDialog(
            SetCurrentWatermark_Instance.this,
            "Current watermark name is "
                + SubstanceLookAndFeel
                    .getCurrentWatermarkName());
      }
    });

    controls.add(getWatermarkName);

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

The screenshot below shows application frame under default watermark (Stripes):

The screenshot below shows the result of calling this API with SubstanceBinaryWatermark instance: