Substance API

View all API methods.

View all client properties.


API method

public static void setBasicFontSize(int value)

Description

Sets the new basic font size.

Parameters:

  • value - New value for basic font size.

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 javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.jvnet.substance.SubstanceLookAndFeel;

/**
 * Test application that shows the use of the
 {@link SubstanceLookAndFeel#setBasicFontSize(int)} APIs.
 
 @author Kirill Grouchnikov
 @see SubstanceLookAndFeel#setBasicFontSize(int)
 */
public class SetBasicFontSize extends JFrame {
  /**
   * Creates the main frame for <code>this</code> sample.
   */
  public SetBasicFontSize() {
    super("Set basic font size");

    this.setLayout(new BorderLayout());

    JPanel panel = new JPanel(new FlowLayout());

    // create a slider to control the basic font size.
    final JSlider basicFontSizeSlider = new JSlider(520,
        SubstanceLookAndFeel.getBasicFontSize());
    basicFontSizeSlider.setPaintLabels(true);
    basicFontSizeSlider.setPaintTicks(true);
    basicFontSizeSlider.setMajorTickSpacing(5);
    basicFontSizeSlider.setMinorTickSpacing(1);
    basicFontSizeSlider.setSnapToTicks(true);

    basicFontSizeSlider.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent e) {
        // if the value is adjusting - ignore. This is done
        // to make CPU usage better.
        if (basicFontSizeSlider.getValueIsAdjusting())
          return;
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            // Set the basic font size
            SubstanceLookAndFeel
                .setBasicFontSize(basicFontSizeSlider
                    .getValue());
            // reset the LAF to have the changes
            try {
              UIManager
                  .setLookAndFeel(new SubstanceLookAndFeel());
            catch (Exception exc) {
            }
            SwingUtilities
                .updateComponentTreeUI(SetBasicFontSize.this);
          }
        });
      }
    });
    panel.add(basicFontSizeSlider);

    this.add(panel, BorderLayout.CENTER);

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

    JButton getBasicFontSize = new JButton("Get current basic font size");
    getBasicFontSize.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        JOptionPane.showMessageDialog(SetBasicFontSize.this,
            "Current basic font size is "
                + SubstanceLookAndFeel.getBasicFontSize());
      }
    });

    controls.add(getBasicFontSize);
    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 SetBasicFontSize().setVisible(true);
      }
    });
  }
}

The screenshot below shows application frame under default font size (11 under Windows) - this method has not been called:

The screenshot below shows application frame after this method has been called with value 14 (note how it affects all UI elements):

The screenshot below shows application frame after this method has been called with value 9 (note how it affects all UI elements):