Java JSlider reapplyFontSize(JSlider slider)

Here you can find the source of reapplyFontSize(JSlider slider)

Description

Apply the font size to the labels of a slider.

License

Open Source License

Parameter

Parameter Description
slider a parameter

Declaration

public static void reapplyFontSize(JSlider slider) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.Component;
import java.awt.Font;
import java.util.Dictionary;
import java.util.Enumeration;

import javax.swing.JSlider;

public class Main {
    /**//w  ww .ja  v a 2s  .c o m
     * Apply the font size to the labels of a slider. This must be called after
     * the labels of a slider are changed.
     *
     * First set up the label hash table and add it to the slider. Then, after
     * the slider has been added to a parent window and had its UI assigned,
     * call this method to change the label sizes.
     *
     * http://nadeausoftware.com/node/93#Settingsliderlabelfontsizes
     * 
     * @param slider
     */
    public static void reapplyFontSize(JSlider slider) {

        Font font = slider.getFont();
        Dictionary dict = slider.getLabelTable();
        Enumeration keys = dict.keys();
        while (keys.hasMoreElements()) {
            Object key = keys.nextElement();
            Component label = (Component) dict.get(key);
            label.setFont(font);
            label.setSize(label.getPreferredSize());
        }

    }
}

Related

  1. createJSlider(final BoundedRangeModel model)
  2. createLabelField(String preText, String postText, JSlider s)
  3. createSliderPanel(final JSlider slider, String label, int width)
  4. fixWinSliderUI(JSlider s)
  5. makeLabelSliderPanelHorizontal(String text, JSlider slider)
  6. setMinMaxSliderLabels(JSlider slider, String[] labels)
  7. setSliderLabels(JSlider slider, int[] values, String[] labels)
  8. setSliderPercent(JSlider s, double percent)
  9. setSliderValue(JSlider slider, float f)