Substance client properties

View all API methods.

View all client properties.


Client property name

SubstanceLookAndFeel.MENU_GUTTER_FILL_KIND

Description

Property name for specifying menu gutter fill kind. Menu gutter is the part of the menu where checkmarks and icons are painted. The value should be one of MenuGutterFillKind enum. This property can be set globally on the UIManager. The default value is MenuGutterFillKind.HARD.


See also


Sample code

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import org.jvnet.substance.SubstanceDefaultListCellRenderer;
import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.utils.SubstanceCoreUtilities;
import org.jvnet.substance.utils.SubstanceConstants.MenuGutterFillKind;

import test.Check;

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

    this.setLayout(new BorderLayout());

    // create sample menu bar with one menu and a few menu items
    JMenuBar jmb = new JMenuBar();
    JMenu menu = new JMenu("menu");
    menu.add(new JMenuItem("test item 1", Check.getIcon("flag_mexico")));
    menu.add(new JMenuItem("test item 2"));
    menu.add(new JMenuItem("test item 3"));
    menu.addSeparator();
    menu.add(new JMenuItem("test menu item 4"));
    menu
        .add(new JMenuItem("test menu item 5", Check
            .getIcon("flag_sweden")));
    menu.add(new JMenuItem("test menu item 6"));
    jmb.add(menu);

    this.setJMenuBar(jmb);

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));

    final JComboBox menuGutterFillCombo = new JComboBox(new Object[] {
        MenuGutterFillKind.NONE, MenuGutterFillKind.SOFT,
        MenuGutterFillKind.HARD, MenuGutterFillKind.SOFT_FILL,
        MenuGutterFillKind.HARD_FILL });
    menuGutterFillCombo.setRenderer(new SubstanceDefaultListCellRenderer() {
      @Override
      public Component getListCellRendererComponent(JList list,
          Object value, int index, boolean isSelected,
          boolean cellHasFocus) {
        MenuGutterFillKind mgfk = (MenuGutterFillKindvalue;
        return super.getListCellRendererComponent(list, mgfk.name()
            .toLowerCase(), index, isSelected, cellHasFocus);
      }
    });
    menuGutterFillCombo.setSelectedItem(SubstanceCoreUtilities
        .getMenuGutterFillKind());
    menuGutterFillCombo.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        // based on the selected item, set the global menu gutter
        // fill kind
        UIManager.put(SubstanceLookAndFeel.MENU_GUTTER_FILL_KIND,
            menuGutterFillCombo.getSelectedItem());
      }
    });
    controls.add(new JLabel("Menu fill"));
    controls.add(menuGutterFillCombo);

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

The screenshot below shows application frame with menu under the default MenuGutterFillKind.HARD fill kind:

The screenshot below shows application frame with menu under the MenuGutterFillKind.SOFT fill kind: