Substance API

View all API methods.

View all client properties.


API method

public static boolean setCurrentTitlePainter(
      SubstanceTitlePainter currentTitlePainter)

Description

Sets new title painter.

Parameters:

  • currentTitlePainter - Title painter object.

Returns:

  • The status of the title painter 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.title.ClassicTitlePainter;

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

    this.setLayout(new BorderLayout());

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

    JButton getTitlePainterName = new JButton(
        "Get current title painter name");
    getTitlePainterName.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        JOptionPane.showMessageDialog(
            SetCurrentTitlePainter_Instance.this,
            "Current title painter name is "
                + SubstanceLookAndFeel
                    .getCurrentTitlePainterName());
      }
    });

    controls.add(getTitlePainterName);

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

The screenshot below shows application frame under default title painter (Glass). Note the title bar fill:

The screenshot below shows the result of calling this API with ClassicTitlePainter instance. Note the flat title bar fill: