Java Code Examples for javax.swing.UIDefaults#keySet()

The following examples show how to use javax.swing.UIDefaults#keySet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LittleLuckLookAndFeel.java    From littleluck with Apache License 2.0 6 votes vote down vote up
/**
 * setting global font.
 * 
 * @param f Font object
 */
public void setApplicationFont(Font f)
{
    UIDefaults defaults = UIManager.getLookAndFeelDefaults();

    synchronized (defaults)
    {
        for (Object ui_property : defaults.keySet())
        {
            if (ui_property.toString().endsWith(".font"))
            {
                UIManager.put(ui_property, f);
            }
        }
    }
}
 
Example 2
Source File: StyledLookAndFeel.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the default font size used in components.
 *
 * @param size new font size
 */
public void setDefaultFontSize(final int size) {
	UIDefaults defaults = getDefaults();

	for (Object key : defaults.keySet()) {
		if ((key instanceof String) && (((String) key).endsWith(".font"))) {
			FontUIResource font = (FontUIResource) defaults.get(key);
			// For some reason changing it in defaults does not work
			// reliably. Going through UIManager fixes it.
			UIManager.put(key, new FontUIResource(font.getName(), font.getStyle(), size));
		}
	}
}
 
Example 3
Source File: FlatLaf.java    From FlatLaf with Apache License 2.0 4 votes vote down vote up
private void initFonts( UIDefaults defaults ) {
	FontUIResource uiFont = null;

	if( SystemInfo.IS_WINDOWS ) {
		Font winFont = (Font) Toolkit.getDefaultToolkit().getDesktopProperty( "win.messagebox.font" );
		if( winFont != null )
			uiFont = createCompositeFont( winFont.getFamily(), winFont.getStyle(), winFont.getSize() );

	} else if( SystemInfo.IS_MAC ) {
		String fontName;
		if( SystemInfo.IS_MAC_OS_10_15_CATALINA_OR_LATER ) {
			// use Helvetica Neue font
			fontName = "Helvetica Neue";
		} else if( SystemInfo.IS_MAC_OS_10_11_EL_CAPITAN_OR_LATER ) {
			// use San Francisco Text font
			fontName = ".SF NS Text";
		} else {
			// default font on older systems (see com.apple.laf.AquaFonts)
			fontName = "Lucida Grande";
		}

		uiFont = createCompositeFont( fontName, Font.PLAIN, 13 );

	} else if( SystemInfo.IS_LINUX ) {
		Font font = LinuxFontPolicy.getFont();
		uiFont = (font instanceof FontUIResource) ? (FontUIResource) font : new FontUIResource( font );
	}

	if( uiFont == null )
		uiFont = createCompositeFont( Font.SANS_SERIF, Font.PLAIN, 12 );

	uiFont = UIScale.applyCustomScaleFactor( uiFont );

	// use active value for all fonts to allow changing fonts in all components
	// (similar as in Nimbus L&F) with:
	//     UIManager.put( "defaultFont", myFont );
	Object activeFont =  new ActiveFont( 1 );

	// override fonts
	for( Object key : defaults.keySet() ) {
		if( key instanceof String && (((String)key).endsWith( ".font" ) || ((String)key).endsWith( "Font" )) )
			defaults.put( key, activeFont );
	}

	// use smaller font for progress bar
	defaults.put( "ProgressBar.font", new ActiveFont( 0.85f ) );

	// set default font
	defaults.put( "defaultFont", uiFont );
}