Class FlatLaf
- java.lang.Object
-
- javax.swing.LookAndFeel
-
- javax.swing.plaf.basic.BasicLookAndFeel
-
- com.formdev.flatlaf.FlatLaf
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
FlatDarkLaf,FlatLightLaf,FlatPropertiesLaf,IntelliJTheme.ThemeLaf
public abstract class FlatLaf extends javax.swing.plaf.basic.BasicLookAndFeelThe base class for all Flat LaFs.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classFlatLaf.ActiveFontstatic interfaceFlatLaf.DisabledIconProviderA provider for disabled icons.private classFlatLaf.FlatUIDefaultsprivate static classFlatLaf.ImageIconUIResource
-
Field Summary
Fields Modifier and Type Field Description private static booleanaquaLoadedprivate static java.util.List<java.lang.Object>customDefaultsSourcesprivate static java.lang.StringDESKTOPFONTHINTSprivate java.beans.PropertyChangeListenerdesktopPropertyListenerprivate java.lang.StringdesktopPropertyNameprivate java.lang.StringdesktopPropertyName2private java.util.Map<java.lang.String,java.lang.String>extraDefaultsprivate static java.util.Map<java.lang.String,java.lang.String>globalExtraDefaultsprivate LinuxPopupMenuCancelerlinuxPopupMenuCancelerprivate MnemonicHandlermnemonicHandlerstatic java.lang.ObjectNULL_VALUESpecial value returned by functions used inrunWithUIDefaultsGetter(Function, Runnable)orregisterUIDefaultsGetter(Function)to indicate that the UI value should becomenull.private javax.swing.PopupFactoryoldPopupFactoryprivate java.util.function.Consumer<javax.swing.UIDefaults>postInitializationprivate static java.lang.StringpreferredFontFamilyprivate static java.lang.StringpreferredLightFontFamilyprivate static java.lang.StringpreferredMonospacedFontFamilyprivate static java.lang.StringpreferredSemiboldFontFamilyprivate booleansubMenuUsabilityHelperInstalledprivate static java.util.function.Function<java.lang.String,java.awt.Color>systemColorGetterprivate java.util.List<java.util.function.Function<java.lang.Object,java.lang.Object>>uiDefaultsGettersprivate static java.util.Set<java.lang.String>uiKeyPlatformPrefixesprivate static java.util.Set<java.lang.String>uiKeySpecialPrefixesprivate static booleanupdateUIPending
-
Constructor Summary
Constructors Constructor Description FlatLaf()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private static voidaddLazyUIdelegateClassLoading(javax.swing.UIDefaults defaults)Handle UI delegate classes if running in special application where multiple class loaders are involved.(package private) voidapplyAdditionalProperties(java.util.Properties properties)static javax.swing.UIDefaults.ActiveValuecreateActiveFontValue(float scaleFactor)(package private) static javax.swing.plaf.FontUIResourcecreateCompositeFont(java.lang.String family, int style, int size)static voiddisableWindowsD3Donscreen()Disable usage of Windows Direct3D (DirectX) onscreen surfaces because this may lead to repaint issues (ghosting) on some systems (probably depending on graphics card/driver).booleanequals(java.lang.Object obj)private java.lang.ObjectfallbackAATextInfo()protected java.util.PropertiesgetAdditionalDefaults()(package private) static java.util.List<java.lang.Object>getCustomDefaultsSources()javax.swing.UIDefaultsgetDefaults()javax.swing.IcongetDisabledIcon(javax.swing.JComponent component, javax.swing.Icon icon)java.util.Map<java.lang.String,java.lang.String>getExtraDefaults()Gets extra UI defaults; ornull.static java.util.Map<java.lang.String,java.lang.String>getGlobalExtraDefaults()Gets global extra UI defaults; ornull.java.lang.StringgetID()Returns the look and feel identifier.protected java.util.List<java.lang.Class<?>>getLafClassesForDefaultsLoading()static java.lang.StringgetPreferredFontFamily()Returns the preferred font family to be used for (nearly) all fonts; ornull.static java.lang.StringgetPreferredLightFontFamily()Returns the preferred font family to be used for "light" fonts; ornull.static java.lang.StringgetPreferredMonospacedFontFamily()Returns the preferred font family to be used for monospaced fonts; ornull.static java.lang.StringgetPreferredSemiboldFontFamily()Returns the preferred font family to be used for "semibold" fonts; ornull.static java.util.Map<java.lang.String,java.lang.Class<?>>getStyleableInfos(javax.swing.JComponent c)Returns information about styleable values of a component.static <T> TgetStyleableValue(javax.swing.JComponent c, java.lang.String key)Returns the (styled) value for the given key from the given component.booleangetSupportsWindowDecorations()Returns whether FlatLaf supports custom window decorations.static java.util.function.Function<java.lang.String,java.awt.Color>getSystemColorGetter()Returns the system color getter function, ornull.static java.lang.StringgetUIKeyLightOrDarkPrefix(boolean dark)Returns UI key prefix, used in FlatLaf properties files, for light or dark themes.static java.util.Set<java.lang.String>getUIKeyPlatformPrefixes()Returns set of UI key prefixes, used in FlatLaf properties files, for current platform.static java.util.Set<java.lang.String>getUIKeySpecialPrefixes()Returns set of special UI key prefixes, used in FlatLaf properties files.inthashCode()static voidhideMnemonics()private voidinitDefaultFont(javax.swing.UIDefaults defaults)private voidinitFonts(javax.swing.UIDefaults defaults)voidinitialize()private voidinitializeAqua()Initialize Aqua LaF on macOS, which is required for using Mac screen menubar.static voidinitIconColors(javax.swing.UIDefaults defaults, boolean dark)Adds the default color palette for action icons and object icons to the given UIDefaults.private voidinitResourceBundle(javax.swing.UIDefaults defaults, java.lang.String bundleName)static booleaninstall(javax.swing.LookAndFeel newLookAndFeel)Deprecated.usesetup(LookAndFeel)instead; this method will be removed in a future versionstatic voidinstallLafInfo(java.lang.String lafName, java.lang.Class<? extends javax.swing.LookAndFeel> lafClass)Adds the given look and feel to the set of available look and feels.abstract booleanisDark()private static booleanisDisplayableFrameOrDialog(java.awt.Window w)static booleanisLafDark()Checks whether the current look and feel is dark.booleanisNativeLookAndFeel()static booleanisShowMnemonics()booleanisSupportedLookAndFeel()static booleanisUseNativeWindowDecorations()Returns whether native window decorations are enabled.static java.lang.ObjectparseDefaultsValue(java.lang.String key, java.lang.String value, java.lang.Class<?> valueType)Parses a UI defaults value string and converts it into a binary object.private voidputAATextInfo(javax.swing.UIDefaults defaults)private voidputDefaults(javax.swing.UIDefaults defaults, java.lang.Object value, java.lang.String... keys)static voidregisterCustomDefaultsSource(java.io.File folder)Registers a folder where FlatLaf searches for properties files with custom UI defaults.static voidregisterCustomDefaultsSource(java.lang.String packageName)Registers a package where FlatLaf searches for properties files with custom UI defaults.static voidregisterCustomDefaultsSource(java.lang.String packageName, java.lang.ClassLoader classLoader)Registers a package where FlatLaf searches for properties files with custom UI defaults.static voidregisterCustomDefaultsSource(java.net.URL packageUrl)Registers a package where FlatLaf searches for properties files with custom UI defaults.voidregisterUIDefaultsGetter(java.util.function.Function<java.lang.Object,java.lang.Object> uiDefaultsGetter)Registers a UI defaults getter function that is invoked before the standard getter.static voidrepaintAllFramesAndDialogs()Repaint all displayable frames and dialogs.private static voidreSetLookAndFeel()static voidrevalidateAndRepaintAllFramesAndDialogs()Revalidate and repaint all displayable frames and dialogs.static voidrunWithUIDefaultsGetter(java.util.function.Function<java.lang.Object,java.lang.Object> uiDefaultsGetter, java.lang.Runnable runnable)Registers a UI defaults getter function that is invoked before the standard getter, runs the given runnable and unregisters the UI defaults getter function again.voidsetExtraDefaults(java.util.Map<java.lang.String,java.lang.String> extraDefaults)Sets extra UI defaults, which are only used when setting up the application look and feel.static voidsetGlobalExtraDefaults(java.util.Map<java.lang.String,java.lang.String> globalExtraDefaults)Sets global extra UI defaults, which are only used when setting up the application look and feel.static voidsetPreferredFontFamily(java.lang.String preferredFontFamily)Sets the preferred font family to be used for (nearly) all fonts.static voidsetPreferredLightFontFamily(java.lang.String preferredLightFontFamily)Sets the preferred font family to be used for "light" fonts.static voidsetPreferredMonospacedFontFamily(java.lang.String preferredMonospacedFontFamily)Sets the preferred font family to be used for monospaced fonts.static voidsetPreferredSemiboldFontFamily(java.lang.String preferredSemiboldFontFamily)Sets the preferred font family to be used for "semibold" fonts.static voidsetSystemColorGetter(java.util.function.Function<java.lang.String,java.awt.Color> systemColorGetter)Sets a system color getter function that is invoked when functionsystemColor()is used in FlatLaf properties files.static booleansetup(javax.swing.LookAndFeel newLookAndFeel)Sets the application look and feel to the given LaF usingUIManager.setLookAndFeel(javax.swing.LookAndFeel).static voidsetUseNativeWindowDecorations(boolean enabled)Sets whether native window decorations are enabled.static voidshowMnemonics(java.awt.Component c)static booleansupportsNativeWindowDecorations()Returns whether native window decorations are supported on current platform.voiduninitialize()static voidunregisterCustomDefaultsSource(java.io.File folder)static voidunregisterCustomDefaultsSource(java.lang.String packageName)static voidunregisterCustomDefaultsSource(java.lang.String packageName, java.lang.ClassLoader classLoader)static voidunregisterCustomDefaultsSource(java.net.URL packageUrl)voidunregisterUIDefaultsGetter(java.util.function.Function<java.lang.Object,java.lang.Object> uiDefaultsGetter)Unregisters a UI defaults getter function that was invoked before the standard getter.static voidupdateUI()Update UI of all application windows immediately.static voidupdateUILater()Update UI of all application windows later.-
Methods inherited from class javax.swing.plaf.basic.BasicLookAndFeel
createAudioAction, getAudioActionMap, initClassDefaults, initComponentDefaults, initSystemColorDefaults, loadSystemColors, playSound
-
Methods inherited from class javax.swing.LookAndFeel
getDescription, getDesktopPropertyValue, getDisabledSelectedIcon, getLayoutStyle, getName, installBorder, installColors, installColorsAndFont, installProperty, loadKeyBindings, makeComponentInputMap, makeIcon, makeInputMap, makeKeyBindings, provideErrorFeedback, toString, uninstallBorder
-
-
-
-
Field Detail
-
DESKTOPFONTHINTS
private static final java.lang.String DESKTOPFONTHINTS
- See Also:
- Constant Field Values
-
customDefaultsSources
private static java.util.List<java.lang.Object> customDefaultsSources
-
globalExtraDefaults
private static java.util.Map<java.lang.String,java.lang.String> globalExtraDefaults
-
extraDefaults
private java.util.Map<java.lang.String,java.lang.String> extraDefaults
-
systemColorGetter
private static java.util.function.Function<java.lang.String,java.awt.Color> systemColorGetter
-
uiKeyPlatformPrefixes
private static java.util.Set<java.lang.String> uiKeyPlatformPrefixes
-
uiKeySpecialPrefixes
private static java.util.Set<java.lang.String> uiKeySpecialPrefixes
-
desktopPropertyName
private java.lang.String desktopPropertyName
-
desktopPropertyName2
private java.lang.String desktopPropertyName2
-
desktopPropertyListener
private java.beans.PropertyChangeListener desktopPropertyListener
-
aquaLoaded
private static boolean aquaLoaded
-
updateUIPending
private static boolean updateUIPending
-
oldPopupFactory
private javax.swing.PopupFactory oldPopupFactory
-
mnemonicHandler
private MnemonicHandler mnemonicHandler
-
subMenuUsabilityHelperInstalled
private boolean subMenuUsabilityHelperInstalled
-
linuxPopupMenuCanceler
private LinuxPopupMenuCanceler linuxPopupMenuCanceler
-
postInitialization
private java.util.function.Consumer<javax.swing.UIDefaults> postInitialization
-
uiDefaultsGetters
private java.util.List<java.util.function.Function<java.lang.Object,java.lang.Object>> uiDefaultsGetters
-
preferredFontFamily
private static java.lang.String preferredFontFamily
-
preferredLightFontFamily
private static java.lang.String preferredLightFontFamily
-
preferredSemiboldFontFamily
private static java.lang.String preferredSemiboldFontFamily
-
preferredMonospacedFontFamily
private static java.lang.String preferredMonospacedFontFamily
-
NULL_VALUE
public static final java.lang.Object NULL_VALUE
Special value returned by functions used inrunWithUIDefaultsGetter(Function, Runnable)orregisterUIDefaultsGetter(Function)to indicate that the UI value should becomenull.- Since:
- 1.6
- See Also:
runWithUIDefaultsGetter(Function, Runnable),registerUIDefaultsGetter(Function)
-
-
Method Detail
-
disableWindowsD3Donscreen
public static void disableWindowsD3Donscreen()
Disable usage of Windows Direct3D (DirectX) onscreen surfaces because this may lead to repaint issues (ghosting) on some systems (probably depending on graphics card/driver). Problem occurs usually when a small heavy-weight popup window (menu, combobox, tooltip) is shown.Sets system property
sun.java2d.d3d.onscreentofalse, but only ifsun.java2d.d3d.onscreen,sun.java2d.d3dandsun.java2d.noddraware not yet set.Note: Must be invoked very early before the graphics environment is created.
This method is automatically invoked when loading this class, which is usually before the graphics environment is created. E.g. when doing
FlatLightLaf.setup()orUIManager.setLookAndFeel( "com.formdev.flatlaf.FlatLightLaf" ).However, it may be invoked too late if you use some methods from
UIManagerofGraphicsEnvironmentbefore setting look and feel. E.g.UIManager.put(Object, Object). In that case invoke this method yourself very early.Tip: How to find out when the graphics environment is created? Set a breakpoint at constructor of class
GraphicsEnvironmentand look at the stack.- Since:
- 3.5.2
-
setup
public static boolean setup(javax.swing.LookAndFeel newLookAndFeel)
Sets the application look and feel to the given LaF usingUIManager.setLookAndFeel(javax.swing.LookAndFeel).- Since:
- 1.2
-
install
@Deprecated public static boolean install(javax.swing.LookAndFeel newLookAndFeel)
Deprecated.usesetup(LookAndFeel)instead; this method will be removed in a future version
-
installLafInfo
public static void installLafInfo(java.lang.String lafName, java.lang.Class<? extends javax.swing.LookAndFeel> lafClass)Adds the given look and feel to the set of available look and feels.Useful if your application uses
UIManager.getInstalledLookAndFeels()to query available LaFs and display them to the user in a combobox.
-
getID
public java.lang.String getID()
Returns the look and feel identifier.Syntax: "FlatLaf - ${theme-name}"
Use
UIManager.getLookAndFeel().getID().startsWith( "FlatLaf" )to check whether the current look and feel is FlatLaf.- Specified by:
getIDin classjavax.swing.LookAndFeel
-
isDark
public abstract boolean isDark()
-
isLafDark
public static boolean isLafDark()
Checks whether the current look and feel is dark.
-
getSupportsWindowDecorations
public boolean getSupportsWindowDecorations()
Returns whether FlatLaf supports custom window decorations. This depends on the operating system and on the used Java runtime.This method returns
trueon Windows 10/11 (see exception below) and on Linux, otherwise returnsfalse.Returns also
falseon Windows 10/11 if FlatLaf native window border support is available (requires Windows 10/11).In these cases, custom decorations are enabled by the root pane. Usage of
JFrame.setDefaultLookAndFeelDecorated(boolean)orJDialog.setDefaultLookAndFeelDecorated(boolean)is not necessary.- Overrides:
getSupportsWindowDecorationsin classjavax.swing.LookAndFeel
-
isNativeLookAndFeel
public boolean isNativeLookAndFeel()
- Specified by:
isNativeLookAndFeelin classjavax.swing.LookAndFeel
-
isSupportedLookAndFeel
public boolean isSupportedLookAndFeel()
- Specified by:
isSupportedLookAndFeelin classjavax.swing.LookAndFeel
-
getDisabledIcon
public javax.swing.Icon getDisabledIcon(javax.swing.JComponent component, javax.swing.Icon icon)- Overrides:
getDisabledIconin classjavax.swing.LookAndFeel
-
initialize
public void initialize()
- Overrides:
initializein classjavax.swing.plaf.basic.BasicLookAndFeel
-
uninitialize
public void uninitialize()
- Overrides:
uninitializein classjavax.swing.plaf.basic.BasicLookAndFeel
-
initializeAqua
private void initializeAqua()
Initialize Aqua LaF on macOS, which is required for using Mac screen menubar. (at least on Java 8, since 9 it seems to work without it)This loads the native library "osxui" and initializes JRSUI. Because both are not unloaded/uninitialized, Aqua LaF is initialized only once.
-
getDefaults
public javax.swing.UIDefaults getDefaults()
- Overrides:
getDefaultsin classjavax.swing.plaf.basic.BasicLookAndFeel
-
applyAdditionalProperties
void applyAdditionalProperties(java.util.Properties properties)
-
getLafClassesForDefaultsLoading
protected java.util.List<java.lang.Class<?>> getLafClassesForDefaultsLoading()
-
getAdditionalDefaults
protected java.util.Properties getAdditionalDefaults()
-
initResourceBundle
private void initResourceBundle(javax.swing.UIDefaults defaults, java.lang.String bundleName)
-
initFonts
private void initFonts(javax.swing.UIDefaults defaults)
-
initDefaultFont
private void initDefaultFont(javax.swing.UIDefaults defaults)
-
createCompositeFont
static javax.swing.plaf.FontUIResource createCompositeFont(java.lang.String family, int style, int size)
-
createActiveFontValue
public static javax.swing.UIDefaults.ActiveValue createActiveFontValue(float scaleFactor)
- Since:
- 1.1
-
initIconColors
public static void initIconColors(javax.swing.UIDefaults defaults, boolean dark)Adds the default color palette for action icons and object icons to the given UIDefaults.This method is public and static to allow using the color palette with other LaFs (e.g. Windows LaF). To do so invoke:
FlatLaf.initIconColors( UIManager.getLookAndFeelDefaults(), false );afterUIManager.setLookAndFeel( ... );.The colors are based on IntelliJ Platform Action icons and Noun icons
These colors may be changed by IntelliJ Platform themes.
-
addLazyUIdelegateClassLoading
private static void addLazyUIdelegateClassLoading(javax.swing.UIDefaults defaults)
Handle UI delegate classes if running in special application where multiple class loaders are involved. E.g. in Eclipse plugin or in LibreOffice extension.Problem: Swing runs in Java's system classloader and FlatLaf is loaded in plugin classloader. When Swing tries to load UI delegate class in
UIDefaults.getUIClass(String, ClassLoader), invoked fromUIDefaults.getUI(JComponent), it uses the component's classloader, which is Java's system classloader for core Swing components, and can not find FlatLaf UI delegates.Solution: Add lazy values for UI delegate class names. Those lazy values use FlatLaf classloader to load UI delegate class. This is similar to what
UIDefaults.getUIClass(String, ClassLoader)does.Not using
defaults.put( "ClassLoader", FlatLaf.class.getClassLoader() ), which would work for FlatLaf UI delegates, but it would break custom UI delegates used in other classloaders.
-
putAATextInfo
private void putAATextInfo(javax.swing.UIDefaults defaults)
-
fallbackAATextInfo
private java.lang.Object fallbackAATextInfo()
-
putDefaults
private void putDefaults(javax.swing.UIDefaults defaults, java.lang.Object value, java.lang.String... keys)
-
getCustomDefaultsSources
static java.util.List<java.lang.Object> getCustomDefaultsSources()
-
registerCustomDefaultsSource
public static void registerCustomDefaultsSource(java.lang.String packageName)
Registers a package where FlatLaf searches for properties files with custom UI defaults.This can be used to specify application specific UI defaults that override UI values of existing themes or to define own UI values used in custom controls.
There may be multiple properties files in that package for multiple themes. The properties file name must match the used theme class names. E.g.
FlatLightLaf.propertiesfor classFlatLightLaforFlatDarkLaf.propertiesfor classFlatDarkLaf.FlatLaf.propertiesis loaded first for all themes.These properties files are loaded after theme and addon properties files and can therefore override all UI defaults.
Invoke this method before setting the look and feel.
If using Java modules, the package must be opened in
module-info.java. Otherwise, useregisterCustomDefaultsSource(URL).- Parameters:
packageName- a package name (e.g. "com.myapp.resources")
-
unregisterCustomDefaultsSource
public static void unregisterCustomDefaultsSource(java.lang.String packageName)
-
registerCustomDefaultsSource
public static void registerCustomDefaultsSource(java.lang.String packageName, java.lang.ClassLoader classLoader)Registers a package where FlatLaf searches for properties files with custom UI defaults.See
registerCustomDefaultsSource(String)for details.- Parameters:
packageName- a package name (e.g. "com.myapp.resources")classLoader- a class loader used to find resources, ornull
-
unregisterCustomDefaultsSource
public static void unregisterCustomDefaultsSource(java.lang.String packageName, java.lang.ClassLoader classLoader)
-
registerCustomDefaultsSource
public static void registerCustomDefaultsSource(java.net.URL packageUrl)
Registers a package where FlatLaf searches for properties files with custom UI defaults.See
registerCustomDefaultsSource(String)for details.This method is useful if using Java modules and the package containing the properties files is not opened in
module-info.java. E.g.FlatLaf.registerCustomDefaultsSource( MyApp.class.getResource( "/com/myapp/themes/" ) ).- Parameters:
packageUrl- a package URL- Since:
- 2
-
unregisterCustomDefaultsSource
public static void unregisterCustomDefaultsSource(java.net.URL packageUrl)
- Since:
- 2
-
registerCustomDefaultsSource
public static void registerCustomDefaultsSource(java.io.File folder)
Registers a folder where FlatLaf searches for properties files with custom UI defaults.See
registerCustomDefaultsSource(String)for details.- Parameters:
folder- a folder
-
unregisterCustomDefaultsSource
public static void unregisterCustomDefaultsSource(java.io.File folder)
-
getGlobalExtraDefaults
public static java.util.Map<java.lang.String,java.lang.String> getGlobalExtraDefaults()
Gets global extra UI defaults; ornull.- Since:
- 2
-
setGlobalExtraDefaults
public static void setGlobalExtraDefaults(java.util.Map<java.lang.String,java.lang.String> globalExtraDefaults)
Sets global extra UI defaults, which are only used when setting up the application look and feel. E.g. usingUIManager.setLookAndFeel(LookAndFeel)orsetup(LookAndFeel).The global extra defaults are useful for smaller additional defaults that may change. Otherwise, FlatLaf properties files should be used. See
registerCustomDefaultsSource(String).The keys and values are strings in same format as in FlatLaf properties files.
Sample that setups "FlatLaf Light" theme with white background color:
FlatLaf.setGlobalExtraDefaults( Collections.singletonMap( "@background", "#fff" ) ); FlatLightLaf.setup();- Since:
- 2
- See Also:
setExtraDefaults(Map)
-
getExtraDefaults
public java.util.Map<java.lang.String,java.lang.String> getExtraDefaults()
Gets extra UI defaults; ornull.- Since:
- 2
-
setExtraDefaults
public void setExtraDefaults(java.util.Map<java.lang.String,java.lang.String> extraDefaults)
Sets extra UI defaults, which are only used when setting up the application look and feel. E.g. usingUIManager.setLookAndFeel(LookAndFeel)orsetup(LookAndFeel).The extra defaults are useful for smaller additional defaults that may change. Otherwise, FlatLaf properties files should be used. See
registerCustomDefaultsSource(String).The keys and values are strings in same format as in FlatLaf properties files.
Sample that setups "FlatLaf Light" theme with white background color:
FlatLaf laf = new FlatLightLaf(); laf.setExtraDefaults( Collections.singletonMap( "@background", "#fff" ) ); FlatLaf.setup( laf );- Since:
- 2
- See Also:
setGlobalExtraDefaults(Map)
-
parseDefaultsValue
public static java.lang.Object parseDefaultsValue(java.lang.String key, java.lang.String value, java.lang.Class<?> valueType) throws java.lang.IllegalArgumentExceptionParses a UI defaults value string and converts it into a binary object.- Parameters:
key- the key, which is used to determine the value type if parametervalueTypeisnullvalue- the value stringvalueType- the expected value type, ornull- Returns:
- the binary value
- Throws:
java.lang.IllegalArgumentException- on syntax errors- Since:
- 2
-
getSystemColorGetter
public static java.util.function.Function<java.lang.String,java.awt.Color> getSystemColorGetter()
Returns the system color getter function, ornull.- Since:
- 3
-
setSystemColorGetter
public static void setSystemColorGetter(java.util.function.Function<java.lang.String,java.awt.Color> systemColorGetter)
Sets a system color getter function that is invoked when functionsystemColor()is used in FlatLaf properties files.The name of the system color is passed as parameter to the function. The function should return
nullfor unknown system colors.Can be used to change the accent color:
FlatLaf.setSystemColorGetter( name -> { return name.equals( "accent" ) ? Color.red : null; } ); FlatLightLaf.setup();- Since:
- 3
-
getUIKeyLightOrDarkPrefix
public static java.lang.String getUIKeyLightOrDarkPrefix(boolean dark)
Returns UI key prefix, used in FlatLaf properties files, for light or dark themes. Return value is either[light]or[dark].- Since:
- 3.6
-
getUIKeyPlatformPrefixes
public static java.util.Set<java.lang.String> getUIKeyPlatformPrefixes()
Returns set of UI key prefixes, used in FlatLaf properties files, for current platform. If UI keys in properties files start with a prefix (e.g.[someprefix]Button.background), then they are only used if that prefix is contained in this set (or is one of[light]or[dark]depending on current theme).By default, the set contains one or more of following prefixes:
[win]on Windows[mac]on macOS[linux]on Linux[unknown]on other platforms[gnome]on Linux with GNOME desktop environment[kde]on Linux with KDE desktop environment- on Linux, the value of the environment variable
XDG_CURRENT_DESKTOP, split at colons and converted to lower case (e.g. if value ofXDG_CURRENT_DESKTOPisubuntu:GNOME, then[ubuntu]and[gnome])
You can add own prefixes to the set. The prefixes must start with '[' and end with ']' characters, otherwise they will be ignored.
- Since:
- 3.6
-
getUIKeySpecialPrefixes
public static java.util.Set<java.lang.String> getUIKeySpecialPrefixes()
Returns set of special UI key prefixes, used in FlatLaf properties files. Unlike other prefixes, properties with special prefixes are preserved. You can access them using `UIManager`. E.g. `UIManager.get( "[someSpecialPrefix]someKey" )`.By default, the set contains following special prefixes:
[style]
You can add own prefixes to the set. The prefixes must start with '[' and end with ']' characters, otherwise they will be ignored.
- Since:
- 3.6
-
reSetLookAndFeel
private static void reSetLookAndFeel()
-
updateUI
public static void updateUI()
Update UI of all application windows immediately. Invoke after changing LaF.
-
updateUILater
public static void updateUILater()
Update UI of all application windows later.
-
supportsNativeWindowDecorations
public static boolean supportsNativeWindowDecorations()
Returns whether native window decorations are supported on current platform.This requires Windows 10/11, but may be disabled if running in special environments (JetBrains Projector, Webswing or WinPE) or if loading native library fails. If system property
FlatSystemProperties.USE_WINDOW_DECORATIONSis set tofalse, then this method also returnsfalse.- Since:
- 1.1.2
-
isUseNativeWindowDecorations
public static boolean isUseNativeWindowDecorations()
Returns whether native window decorations are enabled.- Since:
- 1.1.2
-
setUseNativeWindowDecorations
public static void setUseNativeWindowDecorations(boolean enabled)
Sets whether native window decorations are enabled.Existing frames and dialogs will be updated.
- Since:
- 1.1.2
-
revalidateAndRepaintAllFramesAndDialogs
public static void revalidateAndRepaintAllFramesAndDialogs()
Revalidate and repaint all displayable frames and dialogs.Useful to update UI after changing
TitlePane.menuBarEmbedded.- Since:
- 1.1.2
-
repaintAllFramesAndDialogs
public static void repaintAllFramesAndDialogs()
Repaint all displayable frames and dialogs.Useful to update UI after changing
TitlePane.unifiedBackground,MenuItem.selectionTypeorComponent.hideMnemonics.- Since:
- 1.1.2
-
isDisplayableFrameOrDialog
private static boolean isDisplayableFrameOrDialog(java.awt.Window w)
-
isShowMnemonics
public static boolean isShowMnemonics()
-
showMnemonics
public static void showMnemonics(java.awt.Component c)
-
hideMnemonics
public static void hideMnemonics()
-
equals
public final boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public final int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
registerUIDefaultsGetter
public void registerUIDefaultsGetter(java.util.function.Function<java.lang.Object,java.lang.Object> uiDefaultsGetter)
Registers a UI defaults getter function that is invoked before the standard getter. This allows using different UI defaults for special purposes (e.g. using multiple themes at the same time).The key is passed as parameter to the function. If the function returns
null, then the next registered function is invoked. If all registered functions returnnull, then the current look and feel is asked. If the function returnsNULL_VALUE, then the UI value becomesnull.- Since:
- 1.6
- See Also:
unregisterUIDefaultsGetter(Function),runWithUIDefaultsGetter(Function, Runnable)
-
unregisterUIDefaultsGetter
public void unregisterUIDefaultsGetter(java.util.function.Function<java.lang.Object,java.lang.Object> uiDefaultsGetter)
Unregisters a UI defaults getter function that was invoked before the standard getter.- Since:
- 1.6
- See Also:
registerUIDefaultsGetter(Function),runWithUIDefaultsGetter(Function, Runnable)
-
runWithUIDefaultsGetter
public static void runWithUIDefaultsGetter(java.util.function.Function<java.lang.Object,java.lang.Object> uiDefaultsGetter, java.lang.Runnable runnable)Registers a UI defaults getter function that is invoked before the standard getter, runs the given runnable and unregisters the UI defaults getter function again. This allows using different UI defaults for special purposes (e.g. using multiple themes at the same time). If the current look and feel is not FlatLaf, then the getter is ignored and the given runnable invoked.The key is passed as parameter to the function. If the function returns
null, then the next registered function is invoked. If all registered functions returnnull, then the current look and feel is asked. If the function returnsNULL_VALUE, then the UI value becomesnull.Example:
// create secondary theme UIDefaults darkDefaults = new FlatDarkLaf().getDefaults(); // create panel using secondary theme FlatLaf.runWithUIDefaultsGetter( key -> { Object value = darkDefaults.get( key ); return (value != null) ? value : FlatLaf.NULL_VALUE; }, () -> { // TODO create components that should use secondary theme here } );- Since:
- 1.6
- See Also:
registerUIDefaultsGetter(Function),unregisterUIDefaultsGetter(Function)
-
getStyleableInfos
public static java.util.Map<java.lang.String,java.lang.Class<?>> getStyleableInfos(javax.swing.JComponent c)
Returns information about styleable values of a component.This is equivalent to:
((StyleableUI)c.getUI()).getStyleableInfos(c)- Since:
- 2.5
-
getStyleableValue
public static <T> T getStyleableValue(javax.swing.JComponent c, java.lang.String key)Returns the (styled) value for the given key from the given component.This is equivalent to:
((StyleableUI)c.getUI()).getStyleableValue(c, key)- Since:
- 2.5
-
getPreferredFontFamily
public static java.lang.String getPreferredFontFamily()
Returns the preferred font family to be used for (nearly) all fonts; ornull.- Since:
- 3
-
setPreferredFontFamily
public static void setPreferredFontFamily(java.lang.String preferredFontFamily)
Sets the preferred font family to be used for (nearly) all fonts.Note: This must be invoked before setting the application look and feel.
- Since:
- 3
-
getPreferredLightFontFamily
public static java.lang.String getPreferredLightFontFamily()
Returns the preferred font family to be used for "light" fonts; ornull.- Since:
- 3
-
setPreferredLightFontFamily
public static void setPreferredLightFontFamily(java.lang.String preferredLightFontFamily)
Sets the preferred font family to be used for "light" fonts.Note: This must be invoked before setting the application look and feel.
- Since:
- 3
-
getPreferredSemiboldFontFamily
public static java.lang.String getPreferredSemiboldFontFamily()
Returns the preferred font family to be used for "semibold" fonts; ornull.- Since:
- 3
-
setPreferredSemiboldFontFamily
public static void setPreferredSemiboldFontFamily(java.lang.String preferredSemiboldFontFamily)
Sets the preferred font family to be used for "semibold" fonts.Note: This must be invoked before setting the application look and feel.
- Since:
- 3
-
getPreferredMonospacedFontFamily
public static java.lang.String getPreferredMonospacedFontFamily()
Returns the preferred font family to be used for monospaced fonts; ornull.- Since:
- 3
-
setPreferredMonospacedFontFamily
public static void setPreferredMonospacedFontFamily(java.lang.String preferredMonospacedFontFamily)
Sets the preferred font family to be used for monospaced fonts.Note: This must be invoked before setting the application look and feel.
- Since:
- 3
-
-