Substance client properties

View all API methods.

View all client properties.


Client property name

SubstanceLookAndFeel.TOOLBAR_BUTTON_FLAT

Description

Client property name for specifying that the toolbar buttons should be flat (no background when non-selected and non-rollover). The value should be an instance of Boolean. The default value is true. This property can be specified on a single button, on a single JToolBar or globally on UIManager.


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.utils.SubstanceCoreUtilities;

import test.Check;

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

    this.setLayout(new BorderLayout());

    // create toolbar with a few toggle buttons and regular buttons
    final JToolBar toolbar = new JToolBar();
    JToggleButton tb1 = new JToggleButton(Check.getIcon("flag_mexico"));
    JToggleButton tb2 = new JToggleButton(Check.getIcon("flag_sweden"));
    JToggleButton tb3 = new JToggleButton(Check.getIcon("flag_hong_kong"));
    ButtonGroup bg = new ButtonGroup();
    bg.add(tb1);
    bg.add(tb2);
    bg.add(tb3);
    toolbar.add(tb1);
    toolbar.add(tb2);
    toolbar.add(tb3);

    toolbar.add(new JButton("test1", Check.getIcon("flag_mexico")));
    toolbar.add(new JButton("test2", Check.getIcon("flag_sweden")));
    toolbar.add(new JButton("test3", Check.getIcon("flag_hong_kong")));

    this.add(toolbar, BorderLayout.NORTH);

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    final JCheckBox isToolbarButtonFlat = new JCheckBox(
        "toolbar buttons flat");
    isToolbarButtonFlat.setSelected(SubstanceCoreUtilities
        .isToolbarButtonFlat(tb1));
    isToolbarButtonFlat.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            // based on checkbox selection, mark toolbar to have
            // non-flat buttons
            toolbar.putClientProperty(
                SubstanceLookAndFeel.TOOLBAR_BUTTON_FLAT,
                isToolbarButtonFlat.isSelected() null
                    : Boolean.FALSE);
            repaint();
          }
        });
      }
    });
    controls.add(isToolbarButtonFlat);
    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 ToolbarButtonFlat().setVisible(true);
      }
    });
  }
}

The screenshot below shows a toolbar in default state - this property is not specified. Note that all the buttons have flat appearance.

The screenshot below shows a toolbar in default state - this property is not specified. Note that all the buttons have flat appearance, except the button under mouse pointer.

The screenshot below shows a toolbar in non-flat state - this property is set to Boolean.TRUE.