Here you can find the source of changeFont(JComponent comp, double scaleFactor, int style)
Parameter | Description |
---|---|
comp | the component for which the font has to be changed |
scaleFactor | the scale factor (the result will be rounded to an integer) |
style | the new style |
public static void changeFont(JComponent comp, double scaleFactor, int style)
//package com.java2s; //License from project: Apache License import java.awt.Font; import javax.swing.JComponent; public class Main { /**/*w w w .j ava 2s . c o m*/ * Scale the original font of a component by a given factor * * @param comp * the component for which the font has to be changed * @param scaleFactor * the scale factor (the result will be rounded to an integer) */ public static void changeFont(JComponent comp, double scaleFactor) { Font font = comp.getFont(); comp.setFont(scale(font, scaleFactor)); } /** * Change the font style of a component * * @param comp * the component for which the font has to be changed * @param style * the new style */ public static void changeFont(JComponent comp, int style) { Font font = comp.getFont(); comp.setFont(font.deriveFont(style)); } /** * Scale the original font of a component by a given factor and change the style * * @param comp * the component for which the font has to be changed * @param scaleFactor * the scale factor (the result will be rounded to an integer) * @param style * the new style */ public static void changeFont(JComponent comp, double scaleFactor, int style) { Font font = comp.getFont(); font = scale(font, scaleFactor); comp.setFont(font.deriveFont(style)); } private static Font scale(Font font, double factor) { int newSize = Math.round((float) (font.getSize() * factor)); return font.deriveFont((float) newSize); } }