### Basic FlatLaf Customization Example Source: https://www.formdev.com/flatlaf/how-to-customize Example demonstrating basic FlatLaf customization by setting component arc and tabbed pane background color. Ensure UIManager.put() is called after FlatLightLaf.setup() and before component creation. ```java FlatLightLaf.setup(); UIManager.put( "Component.arc", 0 ); UIManager.put( "ProgressBar.arc", 0 ); UIManager.put( "TabbedPane.selectedBackground", Color.white ); ``` -------------------------------- ### Setup FlatLightLaf Source: https://www.formdev.com/flatlaf Enable FlatLaf's light theme by calling FlatLightLaf.setup() before creating any Swing components. This is the recommended way to integrate FlatLaf. ```java FlatLightLaf.setup(); // create UI here... ``` -------------------------------- ### Basic Properties File Structure Source: https://www.formdev.com/flatlaf/properties-files Example of a simple properties file defining button colors. Lines starting with '#' are comments. ```properties # button colors Button.background = #ffffff Button.focusedBackground = #e3f1fa ``` -------------------------------- ### Setup FlatLaf with Custom Defaults Source: https://www.formdev.com/flatlaf/how-to-customize In your main method, register the custom defaults source and then set up the desired FlatLaf theme. This ensures your custom properties are loaded. ```java FlatLaf.registerCustomDefaultsSource( "com.myapp.themes" ); FlatLightLaf.setup(); ``` -------------------------------- ### Apply Custom Theme in Main Method Source: https://www.formdev.com/flatlaf/how-to-customize In your application's main method, call the setup method of your custom theme class to apply it. ```java MyDarkerLaf.setup(); ``` -------------------------------- ### Setup New Theme in Application Source: https://www.formdev.com/flatlaf/theme-editor Add this code to your main method to set up a newly created theme. Ensure it's called before setting the look and feel. ```java MyAppTheme.setup(); ``` -------------------------------- ### Setup FlatLaf via UIManager Source: https://www.formdev.com/flatlaf Alternatively, set FlatLaf's look and feel using UIManager. This method allows for more explicit control and error handling during initialization. ```java try { UIManager.setLookAndFeel( new FlatLightLaf() ); } catch( Exception ex ) { System.err.println( "Failed to initialize LaF" ); } // create UI here... ``` -------------------------------- ### Insets Properties Source: https://www.formdev.com/flatlaf/properties-files Example of defining insets for components like buttons and tabbed panes. ```properties Button.margin = 2,14,2,14 TabbedPane.tabInsets = 0,12,0,12 ``` -------------------------------- ### Define Global Component Defaults Source: https://www.formdev.com/flatlaf/how-to-customize Create a properties file for global defaults that apply to all themes. This example sets the arc for components and progress bars to 0. ```properties Component.arc = 0 ProgressBar.arc = 0 ``` -------------------------------- ### Assembly Descriptor for Packaging Dependencies Source: https://www.formdev.com/flatlaf/native-libraries Define the assembly descriptor file (e.g., zip.xml) to specify how dependencies, including native libraries, should be organized in the application distributable. This example places all dependencies into the 'lib' directory. ```xml zip true zip dir lib ``` -------------------------------- ### Maven Assembly Plugin Configuration Source: https://www.formdev.com/flatlaf/native-libraries Configure the Maven Assembly Plugin to package your application distributable. This example shows how to set up the plugin to include all dependencies, including native libraries, into the 'lib' directory of the zip archive. ```xml ... maven-assembly-plugin package single false src/main/assembly/zip.xml ``` -------------------------------- ### Wildcard Replacements for Component Defaults Source: https://www.formdev.com/flatlaf/properties-files Uses keys starting with '*.' to replace matching keys in `BasicLookAndFeel.getDefaults()` and `FlatLaf.getDefaults()`. This is commonly used for initializing basic component colors. ```properties *.background = #f2f2f2 *.foreground = #000 ``` -------------------------------- ### Maven Central Native Libraries Source: https://www.formdev.com/flatlaf/native-libraries Example of FlatLaf native libraries available on Maven Central for version 3.4. These are typically bundled with the main JAR or can be downloaded separately. ```text https://repo1.maven.org/maven2/com/formdev/flatlaf/3.4/ flatlaf-3.4.jar flatlaf-3.4-no-natives.jar flatlaf-3.4-sources.jar flatlaf-3.4-javadoc.jar flatlaf-3.4-linux-x86_64.so flatlaf-3.4-macos-arm64.dylib flatlaf-3.4-macos-x86_64.dylib flatlaf-3.4-windows-x86_64.dll flatlaf-3.4-windows-x86.dll flatlaf-3.4-windows-arm64.dll ``` -------------------------------- ### Define Light Theme Specific Defaults Source: https://www.formdev.com/flatlaf/how-to-customize Create a properties file for light themes to override specific component appearances and define application-specific colors. This example customizes the selected tab background and sidebar background for light themes. ```properties TabbedPane.selectedBackground = #fff # define application specific UI values MyApp.SideBar.background = darken(@background,10%) MyApp.someColor = #f00 MyApp.anotherColor = #645554 ``` -------------------------------- ### Create a New Custom Theme Class Source: https://www.formdev.com/flatlaf/how-to-customize Subclass FlatDarkLaf to create a new theme. Provide a setup method and override the getName method to define your custom theme's identity. ```java package com.myapp.themes; import com.formdev.flatlaf.FlatDarkLaf; public class MyDarkerLaf extends FlatDarkLaf { public static boolean setup() { return setup( new MyDarkerLaf() ); } @Override public String getName() { return "MyDarkerLaf"; } } ``` -------------------------------- ### Define Style Classes in FlatLaf.properties Source: https://www.formdev.com/flatlaf/typography Example of defining style classes that reference font properties. Used for applying specific font styles to components. ```properties ... [style].h0 = font: $h0.font ... ``` -------------------------------- ### Define Dark Theme Specific Defaults Source: https://www.formdev.com/flatlaf/how-to-customize Create a properties file for dark themes to override specific component appearances and define application-specific colors. This example customizes the selected tab background and sidebar background for dark themes. ```properties TabbedPane.selectedBackground = darken($TabbedPane.background,5%) # define application specific UI values MyApp.SideBar.background = lighten(@background,10%) MyApp.someColor = #00f MyApp.anotherColor = #278354 ``` -------------------------------- ### JPanel as Placeholder for Full Window Buttons (macOS) in Tabbed Pane Source: https://www.formdev.com/flatlaf/client-properties This example shows how to add a JPanel as a placeholder for macOS window buttons as the leading component of a JTabbedPane when in full window content mode. ```java JPanel placeholder = new JPanel(); placeholder.putClientProperty( FlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_PLACEHOLDER, "mac" ); tabbedPane.putClientProperty( FlatClientProperties.TABBED_PANE_LEADING_COMPONENT, placeholder ); ``` -------------------------------- ### Set JButton Button Type Source: https://www.formdev.com/flatlaf/client-properties Use client properties to change the visual style of a JButton. This example sets the button to have round rectangle edges. ```Java myButton.putClientProperty( "JButton.buttonType", "roundRect" ); ``` -------------------------------- ### JTextField.clearCallback with Consumer Source: https://www.formdev.com/flatlaf/client-properties Example of setting a clear callback for a JTextField using a Consumer. The Consumer receives the text field as a parameter, allowing for custom clearing logic. ```java myTextField.putClientProperty( "JTextField.clearCallback", (Consumer) textField -> { // clear field here or cancel search } ); ``` -------------------------------- ### Use FlatClientProperties Constants for JButton Source: https://www.formdev.com/flatlaf/client-properties Leverage constants from FlatClientProperties for setting button types, ensuring type safety and code readability. This example configures a round rectangle button. ```Java myButton.putClientProperty( FlatClientProperties.BUTTON_TYPE, FlatClientProperties.BUTTON_TYPE_ROUND_RECT ); ``` -------------------------------- ### Check Modifier Key Press on Tab Close Source: https://www.formdev.com/flatlaf/client-properties This example shows how to check if a modifier key like Shift was pressed when a tab close button was clicked, by accessing the current AWTEvent. ```java AWTEvent e = EventQueue.getCurrentEvent(); boolean shift = (e instanceof MouseEvent) ? ((MouseEvent)e).isShiftDown() : false; ``` -------------------------------- ### Applying System Theme to FlatLaf Source: https://www.formdev.com/flatlaf/sponsor This Java code demonstrates how to set up FlatLaf's look and feel based on the system's dark mode preference and how to update the UI when the system theme changes. ```java // setup application look and feel if( SystemTheming.isDarkMode() ) FlatDarkLaf.setup(); else FlatLightLaf.setup(); // update application look and feel on OS changes SystemTheming.addListener( e -> { if( e.isDarkMode() ) FlatDarkLaf.setup(); else FlatLightLaf.setup(); FlatLaf.updateUI(); } ); // create UI ... ``` -------------------------------- ### Run Theme Editor Source: https://www.formdev.com/flatlaf/theme-editor Execute the FlatLaf theme editor JAR file. Requires Java 8 or newer. ```bash java -jar flatlaf-theme-editor-.jar ``` -------------------------------- ### SystemTheming Source: https://www.formdev.com/flatlaf/sponsor Provides access to system theme information (light/dark, accent color, etc) and allows listening to changes. ```APIDOC ## Class SystemTheming ### Description Provides access to system theme information (light/dark, accent color, etc) and allows listening to changes. ### Methods #### `isSupportedPlatform()` Returns whether supported on current operating system and CPU architecture. #### `isDarkMode()` Returns whether the operating system theme is dark. #### `getAccentColor()` Returns the operating system theme accent color, or null. #### `getHighlightColor()` Returns the macOS operating system theme highlight color, or null. #### `addListener(Listener l)` Adds a listener. Will be invoked on AWT thread. #### `removeListener(Listener l)` Removes the listener. ### Inner Interfaces #### `interface Listener` ##### Description The listener interface for receiving system theme change events. ##### Methods ###### `systemThemeChanged(Event e)` Called when the system theme has changed. ### Inner Classes #### `class Event` ##### Description A event that indicates that the system theme has changed. ##### Methods ###### `isDarkMode()` Returns whether the system theme is dark. ###### `getAccentColor()` Returns the system theme accent color. ``` -------------------------------- ### JTextField.clearCallback with Runnable Source: https://www.formdev.com/flatlaf/client-properties Example of setting a clear callback for a JTextField using a Runnable. This callback is invoked when the clear button is clicked and is responsible for clearing the text field. ```java myTextField.putClientProperty( "JTextField.clearCallback", (Runnable) () -> { // clear field here or cancel search } ); ``` -------------------------------- ### Primitive Type Properties Source: https://www.formdev.com/flatlaf/properties-files Demonstrates the syntax for boolean, integer, float, and null values in properties files. ```properties # boolean Menu.opaque = false MenuItem.borderPainted = true # integer Button.borderWidth = 1 # float Popup.dropShadowOpacity = 0.15 # null Menu.checkIcon = null ``` -------------------------------- ### Lib/Bin Directory Native Library Layout Source: https://www.formdev.com/flatlaf/native-libraries This layout demonstrates how to organize the FlatLaf JAR in a 'lib' directory and native libraries in a 'bin' directory. ```text lib/flatlaf-3.4.jar bin/flatlaf-3.4-linux-x86_64.so bin/flatlaf-3.4-macos-arm64.dylib bin/flatlaf-3.4-macos-x86_64.dylib bin/flatlaf-3.4-windows-x86_64.dll bin/flatlaf-3.4-windows-x86.dll bin/flatlaf-3.4-windows-arm64.dll ``` -------------------------------- ### Integrate with macOS Application Menu (Java 9+) Source: https://www.formdev.com/flatlaf/macos Use `java.awt.Desktop` to set handlers for the About, Preferences, and Quit menu items. Ensure the respective actions are supported before setting the handlers. ```java Desktop desktop = Desktop.getDesktop(); if( desktop.isSupported( Desktop.Action.APP_ABOUT ) ) { desktop.setAboutHandler( e -> { // show about dialog } ); } if( desktop.isSupported( Desktop.Action.APP_PREFERENCES ) ) { desktop.setPreferencesHandler( e -> { // show preferences dialog } ); } if( desktop.isSupported( Desktop.Action.APP_QUIT_HANDLER ) ) { desktop.setQuitHandler( (e, response) -> { boolean canQuit = // TODO if( canQuit ) response.performQuit(); else response.cancelQuit(); } ); } ``` -------------------------------- ### Select Folder Source: https://www.formdev.com/flatlaf/system-file-chooser Opens a dialog to select a directory. The selected directory path is printed to the console. ```Java SystemFileChooser fc = new SystemFileChooser(); fc.setFileSelectionMode( SystemFileChooser.DIRECTORIES_ONLY ); if( fc.showOpenDialog( this ) == SystemFileChooser.APPROVE_OPTION ) { File directory = fc.getSelectedFile(); System.out.println( directory ); } ``` -------------------------------- ### Set UI Defaults in Properties Files Source: https://www.formdev.com/flatlaf/customizing Set UI defaults in FlatLaf properties files using key-value pairs. ```properties someKey = someValue ``` -------------------------------- ### Color Properties Source: https://www.formdev.com/flatlaf/properties-files Shows how to define colors using hexadecimal formats and color functions. ```properties Button.background = #fff Button.focusedBackground = #e3f1fa PasswordField.capsLockIconColor = #00000064 ``` ```properties TableHeader.separatorColor = darken($TableHeader.background,10%) ``` -------------------------------- ### Implement and Set State Store Source: https://www.formdev.com/flatlaf/system-file-chooser Implements the SystemFileChooser.StateStore interface to persist the last visited folder and sets it for the file chooser. ```Java SystemFileChooser.setStateStore( new SystemFileChooser.StateStore() { private static final String KEY_PREFIX = "fileChooser."; private final Preferences state = Preferences.userRoot().node( "my-application" ); @Override public String get( String key, String def ) { return state.get( KEY_PREFIX + key, def ); } @Override public void put( String key, String value ) { if( value != null ) state.put( KEY_PREFIX + key, value ); else state.remove( KEY_PREFIX + key ); } } ); ``` -------------------------------- ### Load Custom IntelliJ Theme Source: https://www.formdev.com/flatlaf/themes Use this code to load and initialize a custom IntelliJ theme from a .theme.json file within your application's resources. Ensure the file path is correct. ```java IntelliJTheme.setup( MyApp.class.getResourceAsStream( "/com/myapp/themes/arc-theme-orange.theme.json" ) ); // create UI here... ``` -------------------------------- ### Using Variables in Property Values Source: https://www.formdev.com/flatlaf/properties-files Demonstrates how to reference previously defined variables using the '@' prefix within property values. ```properties Table.background = @background Table.foreground = @foreground MenuBar.hoverBackground = @menuHoverBackground MenuItem.acceleratorForeground = lighten(@foreground,30%) ``` -------------------------------- ### Dimension Properties Source: https://www.formdev.com/flatlaf/properties-files Shows how to define dimensions for components like desktop icons and progress bars. ```properties DesktopIcon.iconSize = 64,64 ProgressBar.horizontalSize = 146,4 ``` -------------------------------- ### Activate Editor Shortcut Source: https://www.formdev.com/flatlaf/theme-editor Use this shortcut to activate the editor. ```text F12 ``` -------------------------------- ### Open Multiple Files Source: https://www.formdev.com/flatlaf/system-file-chooser Opens a dialog to select multiple files. The selected files are printed to the console, with each file on a new line. ```Java SystemFileChooser fc = new SystemFileChooser(); fc.setMultiSelectionEnabled( true ); if( fc.showOpenDialog( this ) == SystemFileChooser.APPROVE_OPTION ) { File[] files = chooser.getSelectedFiles(); System.out.println( Arrays.toString( files ).replace( ",", "\n" ) ); } ``` -------------------------------- ### Integrate with macOS Application Menu (Java 8) Source: https://www.formdev.com/flatlaf/macos Use `com.formdev.flatlaf.extras.FlatDesktop` from the flatlaf-extras library to set handlers for About, Preferences, and Quit menu items. This is an alternative for applications using Java 8. ```java FlatDesktop.setAboutHandler( () -> { // show about dialog } ); FlatDesktop.setPreferencesHandler( () -> { // show preferences dialog } ); FlatDesktop.setQuitHandler( response -> { boolean canQuit = // TODO if( canQuit ) response.performQuit(); else response.cancelQuit(); } ); ``` -------------------------------- ### Fat JAR Lib/Bin Directory Native Library Layout Source: https://www.formdev.com/flatlaf/native-libraries This layout illustrates organizing a fat JAR in 'lib' and its native libraries in 'bin'. ```text lib/myapp-1.0.jar bin/myapp-1.0-flatlaf-linux-x86_64.so bin/myapp-1.0-flatlaf-macos-arm64.dylib bin/myapp-1.0-flatlaf-macos-x86_64.dylib bin/myapp-1.0-flatlaf-windows-x86_64.dll bin/myapp-1.0-flatlaf-windows-x86.dll bin/myapp-1.0-flatlaf-windows-arm64.dll ``` -------------------------------- ### SystemTheming API Definition Source: https://www.formdev.com/flatlaf/sponsor This Java class provides methods to query system theme properties like dark mode and accent color, and to register listeners for theme changes. ```java /** * Gives access to system theme information (light/dark, accent color, etc) * and allows listening to changes. */ public class SystemTheming { /** Returns whether supported on current operating system and CPU architecture. */ public static boolean isSupportedPlatform() /** Returns whether the operating system theme is dark. */ public static boolean isDarkMode() /** Returns the operating system theme accent color, or null. */ public static Color getAccentColor() /** Returns the macOS operating system theme highlight color, or null. */ public static Color getHighlightColor() /** Adds a listener. Will be invoked on AWT thread. */ public static void addListener( Listener l ) /** Removes the listener. */ public static void removeListener( Listener l ) /** The listener interface for receiving system theme change events. */ public interface Listener { public void systemThemeChanged( Event e ); } /** A event that indicates that the system theme has changed. */ public static class Event { public boolean isDarkMode() public Color getAccentColor() } } ``` -------------------------------- ### Standard Native Library Layout Source: https://www.formdev.com/flatlaf/native-libraries This layout shows the standard naming convention for FlatLaf JAR and its associated native libraries. ```text flatlaf-3.4.jar flatlaf-3.4-linux-x86_64.so flatlaf-3.4-macos-arm64.dylib flatlaf-3.4-macos-x86_64.dylib flatlaf-3.4-windows-x86_64.dll flatlaf-3.4-windows-x86.dll flatlaf-3.4-windows-arm64.dll ``` -------------------------------- ### Define Custom Theme Properties Source: https://www.formdev.com/flatlaf/how-to-customize Create a properties file with the same basename as your custom theme class to define theme-specific properties like background, foreground, and accent colors. ```properties @background = #111 @foreground = #ddd @accentColor = #f57900 ``` -------------------------------- ### Fat JAR with Native Library Naming Source: https://www.formdev.com/flatlaf/native-libraries This layout shows the naming convention when FlatLaf is repackaged into a fat/uber application JAR. ```text myapp-1.0.jar myapp-1.0-flatlaf-linux-x86_64.so myapp-1.0-flatlaf-macos-arm64.dylib myapp-1.0-flatlaf-macos-x86_64.dylib myapp-1.0-flatlaf-windows-x86_64.dll myapp-1.0-flatlaf-windows-x86.dll myapp-1.0-flatlaf-windows-arm64.dll ``` -------------------------------- ### Applying FlatLaf Styles with CSS Syntax Source: https://www.formdev.com/flatlaf/client-properties Use `FlatLaf.style` to apply styles to a JComponent using CSS-like syntax. This allows for granular control over component appearance. ```Java myComponent.putClientProperty( "FlatLaf.style", "arc: 10;" ); ``` -------------------------------- ### Approve Callback with Message Dialog Source: https://www.formdev.com/flatlaf/system-file-chooser Demonstrates using ApproveContext.showMessageDialog within a callback to display a system message dialog. Avoid showing Swing dialogs directly from the callback. ```Java fc.setApproveCallback( (selectedFiles, context) -> { if( !selectedFiles[0].getName().startsWith( "blabla" ) ) { context.showMessageDialog( JOptionPane.WARNING_MESSAGE, "File name must start with 'blabla' :)", null, 0 ); return SystemFileChooser.CANCEL_OPTION; } return SystemFileChooser.APPROVE_OPTION; } ); ``` -------------------------------- ### Change Color Components (Hue, Saturation, Lightness, Alpha) Source: https://www.formdev.com/flatlaf/properties-files Use `changeHue`, `changeSaturation`, `changeLightness`, or `changeAlpha` to set specific color components to a new value. Hue is in degrees, while saturation, lightness, and alpha are percentages. ```java changeHue(#80e619,70) ``` ```java changeSaturation(#80e619,60%) ``` ```java changeLightness(#80e619,70%) ``` ```java Button.focusedBackground = changeLightness($Component.focusColor,95%) ``` -------------------------------- ### Set System Property via Command Line Source: https://www.formdev.com/flatlaf/system-properties Pass system properties directly when launching an application from the command line. This is useful for quick configuration changes without modifying code. ```bash $ myapp -Dflatlaf.animation=false ``` -------------------------------- ### Referencing Other Properties Source: https://www.formdev.com/flatlaf/properties-files Shows how to reference other property values using the '$' prefix followed by the key. This allows for value reuse and dynamic updates. ```properties Table.background = $List.background Tree.background = $List.background Button.hoverBackground = darken($Button.background,3%,derived) ``` -------------------------------- ### Open Single File Source: https://www.formdev.com/flatlaf/system-file-chooser Opens a dialog to select a single file. The selected file is printed to the console. ```Java SystemFileChooser fc = new SystemFileChooser(); if( fc.showOpenDialog( this ) == SystemFileChooser.APPROVE_OPTION ) { File file = fc.getSelectedFile(); System.out.println( file ); } ``` -------------------------------- ### Enable Full Screen Mode on macOS (Pre Java 11) Source: https://www.formdev.com/flatlaf/macos Allows applications to support macOS full screen mode by setting a client property. Holding Alt while clicking the green button still maximizes the window. ```java frame.getRootPane().putClientProperty( "apple.awt.fullscreenable", true ); ``` -------------------------------- ### Enable FlatLaf Window Decorations on Linux Source: https://www.formdev.com/flatlaf/window-decorations Enable custom window decorations for JFrame and JDialog on Linux systems before creating any UI. This should not be used if your application supports switching Look and Feels dynamically. ```java if( SystemInfo.isLinux ) { // enable custom window decorations JFrame.setDefaultLookAndFeelDecorated( true ); JDialog.setDefaultLookAndFeelDecorated( true ); } ``` -------------------------------- ### Approve Callback with Method Reference Source: https://www.formdev.com/flatlaf/system-file-chooser Sets an approval callback using a method reference. The callback method must return APPROVE_OPTION or CANCEL_OPTION. ```Java fc.setApproveCallback( this::approveCallback ); private boolean approveCallback( File[] selectedFiles, ApproveContext context ) { // do something return SystemFileChooser.APPROVE_OPTION; // or SystemFileChooser.CANCEL_OPTION } ``` -------------------------------- ### Select Contrasting Color Source: https://www.formdev.com/flatlaf/properties-files Use `contrast` to choose between a dark and light color based on their contrast with a given color. A threshold can be specified to adjust the transition point. ```java contrast(#bbb, #00f, #0f0) ``` ```java contrast(#444, #00f, #0f0) ``` ```java @selectionForeground = contrast(@selectionBackground, @foreground, #fff) ``` -------------------------------- ### Applying FlatLaf Styles with a Map Source: https://www.formdev.com/flatlaf/client-properties Use `FlatLaf.style` with a `Map` for applying styles programmatically. Values in the map must be binary. ```Java Map styles = new HashMap<>(); styles.put( "arc", 10 ); myComponent.putClientProperty( "FlatLaf.style", styles ); ``` -------------------------------- ### Configure Global macOS Settings for FlatLaf Source: https://www.formdev.com/flatlaf/macos Use this snippet to enable the screen menu bar, set the application name, and configure the appearance of window title bars for all windows in a macOS application using FlatLaf. ```java public static void main( String[] args ) { // macOS (see https://www.formdev.com/flatlaf/macos/) if( SystemInfo.isMacOS ) { // enable screen menu bar // (moves menu bar from JFrame window to top of screen) System.setProperty( "apple.laf.useScreenMenuBar", "true" ); // application name used in screen menu bar // (in first menu after the "apple" menu) System.setProperty( "apple.awt.application.name", "My Application" ); // appearance of window title bars // possible values: // - "system": use current macOS appearance (light or dark) // - "NSAppearanceNameAqua": use light appearance // - "NSAppearanceNameDarkAqua": use dark appearance // (must be set on main thread and before AWT/Swing is initialized; // setting it on AWT thread does not work) System.setProperty( "apple.awt.application.appearance", "system" ); } SwingUtilities.invokeLater( () -> { FlatLightLaf.setup(); // create and show UI } ); } ``` -------------------------------- ### Font Properties Source: https://www.formdev.com/flatlaf/properties-files Illustrates various ways to define fonts, including size, style, family, and derivation from base fonts. ```properties defaultFont = 13 "Open Sans", "Noto Sans", Roboto, Arial Label.font = +italic h1.font = +12 xxxl.font = bold +36 lightTitle.font = 200% $light.font ``` -------------------------------- ### Always Show Mnemonics using Properties Source: https://www.formdev.com/flatlaf/customizing Set 'Component.hideMnemonics' to false in properties files to make mnemonics always visible, instead of appearing only when Alt is pressed. ```properties Component.hideMnemonics = false ``` -------------------------------- ### Pick Color from Screen Shortcut Source: https://www.formdev.com/flatlaf/theme-editor Use this shortcut to pick a color from anywhere on the screen and insert its value into the editor. Press Esc to cancel. ```text Ctrl+Shift+G ``` -------------------------------- ### Set Platform Specific Properties Source: https://www.formdev.com/flatlaf/system-file-chooser Sets platform-specific properties for the file chooser, such as custom labels or directory handling. ```Java fc.putPlatformProperty( SystemFileChooser.WINDOWS_FILE_NAME_LABEL, "My filename label:" ); fc.putPlatformProperty( SystemFileChooser.MAC_TREATS_FILE_PACKAGES_AS_DIRECTORIES, true ); ``` -------------------------------- ### Custom Icon in Properties Files Source: https://www.formdev.com/flatlaf/properties-files Defines an icon using its fully qualified class name. The class must be public and have a zero-argument public constructor. ```properties CheckBox.icon = com.formdev.flatlaf.icons.FlatCheckBoxIcon ``` -------------------------------- ### Setting Minimum Height for Buttons Source: https://www.formdev.com/flatlaf/client-properties Use `JComponent.minimumHeight` to specify the minimum height for buttons and toggle buttons. ```Java myToggleButton.putClientProperty( "JComponent.minimumHeight", 40 ); ``` -------------------------------- ### System File Chooser API Source: https://www.formdev.com/flatlaf/sponsor Provides access to the system file chooser. Includes a method to check platform support. ```java /** * Gives access to system file chooser. */ public class SystemFileChooser { /** Returns whether supported on current operating system and CPU architecture. */ public static boolean isSupportedPlatform() TBD } ``` -------------------------------- ### Save File Source: https://www.formdev.com/flatlaf/system-file-chooser Opens a dialog to select a file for saving. The selected file path is printed to the console. ```Java SystemFileChooser fc = new SystemFileChooser(); if( fc.showSaveDialog( this ) == SystemFileChooser.APPROVE_OPTION ) { File file = fc.getSelectedFile(); System.out.println( file ); } ``` -------------------------------- ### Configure Main Frame for macOS Specifics Source: https://www.formdev.com/flatlaf/macos Customize the main frame on macOS to hide redundant menu items, handle HTML text in menus, and enable advanced window features like full-window content and transparent title bars. ```java // macOS (see https://www.formdev.com/flatlaf/macos/) if( SystemInfo.isMacOS ) { // hide menu items that are in macOS application menu aboutMenuItem.setVisible( false ); preferencesMenuItem.setVisible( false ); exitMenuItem.setVisible( false ); // do not use HTML text in menu items because this is not supported in macOS screen menu htmlMenuItem.setText( "some text" ); if( SystemInfo.isMacFullWindowContentSupported ) { // expand window content into window title bar and make title bar transparent frame.getRootPane().putClientProperty( "apple.awt.fullWindowContent", true ); frame.getRootPane().putClientProperty( "apple.awt.transparentTitleBar", true ); // hide window title if( SystemInfo.isJava_17_orLater ) frame.getRootPane().putClientProperty( "apple.awt.windowTitleVisible", false ); else frame.setTitle( null ); // add gap to left side of toolbar toolBar.add( Box.createHorizontalStrut( 70 ), 0 ); } // enable full screen mode for this window (for Java 8 - 10; not necessary for Java 11+) if( !SystemInfo.isJava_11_orLater ) frame.getRootPane().putClientProperty( "apple.awt.fullscreenable", true ); } ``` -------------------------------- ### JPanel as Placeholder for Full Window Buttons (macOS) in ToolBar Source: https://www.formdev.com/flatlaf/client-properties This snippet demonstrates adding a JPanel as a placeholder for macOS window buttons directly into a JToolBar. FlatLaf will automatically position it correctly. ```java JPanel placeholder = new JPanel(); placeholder.putClientProperty( FlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_PLACEHOLDER, "mac" ); JToolBar toolBar = new JToolBar(); toolBar.add( placeholder ); // add tool bar items frame.getContentPane().add( toolBar, BorderLayout.NORTH ); ``` -------------------------------- ### Scaled Values for HiDPI Screens Source: https://www.formdev.com/flatlaf/properties-files Specifies values that should be automatically scaled for HiDPI screens. Prefixes include `{scaledInteger}`, `{scaledFloat}`, `{scaledInsets}`, and `{scaledDimension}`. ```properties Caret.width = {scaledInteger}1 Component.innerFocusWidth = {scaledFloat}0.5 TabbedPane.tabInsets = {scaledInsets}0,12,0,12 ColorChooser.swatchesSwatchSize = {scaledDimension}16,16 ``` -------------------------------- ### Create HSL/HSLA Colors Source: https://www.formdev.com/flatlaf/properties-files Use `hsl` for hue, saturation, and lightness, or `hsla` to include an alpha channel. Hue is in degrees (0-360), while saturation, lightness, and alpha are percentages. ```java hsl(90, 100%, 50%) ``` ```java List.selectionBackground = hsl(209,66%,44%) ``` ```java List.selectionForeground = hsla(0,0%,100%,50%) ``` -------------------------------- ### Approve Callback with Lambda Source: https://www.formdev.com/flatlaf/system-file-chooser Sets an approval callback using a lambda expression. The callback is invoked when the user presses 'OK'. It can return CANCEL_OPTION to keep the dialog open. ```Java fc.setApproveCallback( (selectedFiles, context) -> { // do something return SystemFileChooser.APPROVE_OPTION; // or SystemFileChooser.CANCEL_OPTION } ); ``` -------------------------------- ### Create RGB/RGBA Colors Source: https://www.formdev.com/flatlaf/properties-files Use `rgb` for red, green, and blue values, or `rgba` to include an alpha channel. Values can be integers (0-255) or percentages (0-100%). ```java rgb(90, 129, 32) ``` ```java Button.focusedBackground = rgb(227,241,250) ``` ```java PasswordField.capsLockIconColor = rgba(0,0,0,120) ``` -------------------------------- ### Move Lines Shortcut Source: https://www.formdev.com/flatlaf/theme-editor Use these shortcuts to move the current line up or down in the editor. ```text Alt+Up / Alt+Down ``` -------------------------------- ### Custom Borders in Properties Files Source: https://www.formdev.com/flatlaf/properties-files Defines borders using comma-separated values for top, left, bottom, right insets, optionally including line color and thickness. An empty border is created if no lineColor is specified. A line border is created if lineColor is specified. ```properties OptionPane.border = 12,12,12,12 ToolTip.border = 4,6,4,6,#000 ``` -------------------------------- ### Define Font Sizes in FlatLaf.properties Source: https://www.formdev.com/flatlaf/typography Defines various heading and text font sizes relative to the default font. Use $semibold.font for bold variants. ```properties # headings h00.font = +24 h0.font = +18 h1.font = +12 $semibold.font h2.font = +6 $semibold.font h3.font = +3 $semibold.font h4.font = bold h1.regular.font = +12 h2.regular.font = +6 h3.regular.font = +3 # text large.font = +2 medium.font = -1 small.font = -2 mini.font = -3 ``` -------------------------------- ### Register Custom Defaults Source Source: https://www.formdev.com/flatlaf/theme-editor Register custom properties files for theme modifications. Invoke this method before setting the look and feel. ```java FlatLaf.registerCustomDefaultsSource( "com.myapp.themes" ); ``` -------------------------------- ### JPanel as Placeholder for Full Window Buttons (macOS) Source: https://www.formdev.com/flatlaf/client-properties Use this snippet to add a JPanel as a placeholder for macOS window buttons in full window content mode. The placeholder is added to the WEST of a tool bar panel. ```java JPanel placeholder = new JPanel(); placeholder.putClientProperty( FlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_PLACEHOLDER, "mac" ); JToolBar toolBar = new JToolBar(); // add tool bar items JPanel toolBarPanel = new JPanel( new BorderLayout() ); toolBarPanel.add( placeholder, BorderLayout.WEST ); toolBarPanel.add( toolBar, BorderLayout.CENTER ); frame.getContentPane().add( toolBarPanel, BorderLayout.NORTH ); ``` -------------------------------- ### Gradle Dependencies for Native Libraries (Kotlin DSL) Source: https://www.formdev.com/flatlaf/native-libraries Configures Gradle to include FlatLaf and its native libraries as dependencies. The 'no-natives' JAR is also shown as an alternative. ```kotlin plugins { application } dependencies { val flatlafVersion = "3.4" implementation( "com.formdev:flatlaf:${flatlafVersion}" ) implementation( "com.formdev:flatlaf:${flatlafVersion}:linux-x86_64@so" ) implementation( "com.formdev:flatlaf:${flatlafVersion}:macos-arm64@dylib" ) implementation( "com.formdev:flatlaf:${flatlafVersion}:macos-x86_64@dylib" ) implementation( "com.formdev:flatlaf:${flatlafVersion}:windows-x86_64@dll" ) // 32-bit (not needed if you bundle a 64-bit JRE with your application) implementation( "com.formdev:flatlaf:${flatlafVersion}:windows-x86@dll" ) // ARM 64-bit (not needed if your application does not support Windows on ARM) implementation( "com.formdev:flatlaf:${flatlafVersion}:windows-arm64@dll" ) } ``` ```kotlin dependencies { // FlatLaf "no-natives" JAR implementation("com.formdev:flatlaf:${flatlafVersion}:no-natives") // if using other FlatLaf libraries, it is required to exclude "com.formdev:flatlaf" implementation("com.formdev:flatlaf-extras:${flatlafVersion}") { exclude("com.formdev", "flatlaf") } } ``` -------------------------------- ### Setting Minimum Width for Components Source: https://www.formdev.com/flatlaf/client-properties Use `JComponent.minimumWidth` to specify the minimum width for certain components like buttons, combo boxes, and text components. ```Java myButton.putClientProperty( "JComponent.minimumWidth", 150 ); ``` -------------------------------- ### Defining Style Classes in UI Defaults (Java) Source: https://www.formdev.com/flatlaf/client-properties Define style classes in UI defaults using Java code. This is an alternative to using properties files for style definitions. ```Java UIManager.put( "[style]Button.primary", "borderColor: #08f; background: #08f; foreground: #fff" ); UIManager.put( "[style].secondary", "borderColor: #0f8; background: #0f8" ); ``` -------------------------------- ### Applying Style Classes to a Component Source: https://www.formdev.com/flatlaf/client-properties Apply style classes to a JComponent using `FlatLaf.styleClass`. Multiple classes can be applied, separated by spaces. ```Java myComponent.putClientProperty( "FlatLaf.styleClass", "primary secondary" ); ``` -------------------------------- ### Defining Variables in Properties Files Source: https://www.formdev.com/flatlaf/properties-files Defines variables using keys prefixed with '@'. These variables can be used within other property values but are not added to UI defaults. ```properties @background = #f2f2f2 @foreground = #000 @menuHoverBackground = darken(@menuBackground,10%,derived) ``` -------------------------------- ### Duplicate Lines Shortcut Source: https://www.formdev.com/flatlaf/theme-editor Use these shortcuts to duplicate the current line up or down in the editor. ```text Ctrl+Alt+Up / Ctrl+Alt+Down ``` -------------------------------- ### Enable Screen Menu Bar on macOS Source: https://www.formdev.com/flatlaf/macos Move the application's menu bar to the top of the screen. Set this property before any UI code is initialized. ```java System.setProperty( "apple.laf.useScreenMenuBar", "true" ); ``` -------------------------------- ### Mix Two Colors Source: https://www.formdev.com/flatlaf/properties-files Use `mix` to blend two colors together. The `weight` parameter (0-100%) determines the proportion of the first color used in the mix. ```java mix(#ff0000, #0000ff, 50%) ``` ```java TabbedPane.focusColor = mix(@selectionBackground,$TabbedPane.background,10%) ``` -------------------------------- ### Explicit Type Prefixes for Property Values Source: https://www.formdev.com/flatlaf/properties-files Provides explicit type prefixes like `{integer}`, `{float}`, `{string}`, `{color}`, `{dimension}`, etc., when the value type cannot be automatically detected. ```properties Component.innerOutlineWidth = {float}1 Table.intercellSpacing = {dimension}0,0 ``` -------------------------------- ### Defining Style Classes in UI Defaults (CSS) Source: https://www.formdev.com/flatlaf/client-properties Define style classes in UI defaults using CSS syntax for applying styles to components. Rules can be general or type-specific. ```Properties [style]Button.primary = borderColor: #08f; background: #08f; foreground: #fff [style].secondary = borderColor: #0f8; background: #0f8 ``` -------------------------------- ### Show Scroll Bar Buttons Source: https://www.formdev.com/flatlaf/customizing Enable the previous/next arrow buttons for all scroll bars globally. Use component-specific properties for individual scroll panes or bars. ```properties UIManager.put( "ScrollBar.showButtons", true ); ``` ```properties ScrollBar.showButtons = true ``` ```java myScrollPane.putClientProperty( "JScrollBar.showButtons", true ); or myScrollBar.putClientProperty( "JScrollBar.showButtons", true ); ``` -------------------------------- ### Set Style for Typography Source: https://www.formdev.com/flatlaf/typography Apply typography by setting a style string, useful for deriving fonts. Supports variations like bold or different sizes. ```Java myTitleLabel.putClientProperty( "FlatLaf.style", "font: $h1.font" ); ``` ```Java myTitleLabel.putClientProperty( "FlatLaf.style", "font: bold $h1.regular.font" ); ``` ```Java myTitleLabel.putClientProperty( "FlatLaf.style", "font: 200% $light.font" ); ``` -------------------------------- ### Insert Color Shortcut Source: https://www.formdev.com/flatlaf/theme-editor Use this shortcut to open the color chooser dialog and insert a color value into the editor. ```text Ctrl+G ``` -------------------------------- ### Set Square Corners using Properties Source: https://www.formdev.com/flatlaf/customizing Set component corner arcs to 0 in properties files for a square appearance. This applies to buttons, checkboxes, progress bars, and other components. ```properties Button.arc = 0 Component.arc = 0 CheckBox.arc = 0 ProgressBar.arc = 0 ``` -------------------------------- ### Set System Property in Java Code Source: https://www.formdev.com/flatlaf/system-properties Configure FlatLaf behavior programmatically by setting system properties within your Java application. This allows for dynamic configuration based on application logic. ```java System.setProperty( "flatlaf.animation", "false" ); ``` -------------------------------- ### Disable System File Chooser via Command Line Source: https://www.formdev.com/flatlaf/system-file-chooser Configure the system property '-Dflatlaf.useSystemFileChooser=false' when running your Java application from the command line to disable the OS file chooser. ```bash -Dflatlaf.useSystemFileChooser=false ``` -------------------------------- ### Tint or Shade a Color Source: https://www.formdev.com/flatlaf/properties-files Use `tint` to mix a color with white, or `shade` to mix with black. The `weight` parameter controls the intensity of the tint or shade. ```java tint(#ff00ff, 50%) ``` ```java shade(#ff00ff, 50%) ``` ```java @disabledForeground = tint(@foreground,55%) ``` ```java @icon = shade(@background,27%) ``` ```java Component.borderColor = shade(@background,20%) ``` ```java Component.disabledBorderColor = tint($Component.borderColor,20%) ``` -------------------------------- ### Platform-Specific Property Values Source: https://www.formdev.com/flatlaf/properties-files Applies property values only on specific operating systems by prefixing keys with `[win]`, `[mac]`, or `[linux]`. ```properties [win]Button.defaultButtonFollowsFocus = true [mac]OptionPane.isYesLast = true [linux]ScrollBar.minimumThumbSize = 18,18 ``` -------------------------------- ### Show Tab Separators Source: https://www.formdev.com/flatlaf/customizing Enable separator lines between tabs. Use this property to visually distinguish adjacent tabs. ```java UIManager.put( "TabbedPane.showTabSeparators", true ); ``` ```properties TabbedPane.showTabSeparators = true ``` -------------------------------- ### Synchronize Window Title Bar Appearance with System on macOS Source: https://www.formdev.com/flatlaf/macos Ensure window title bars automatically adapt to the system's light or dark appearance. This property must be set on the main thread before AWT/Swing initialization and is available since Java 14. ```java System.setProperty( "apple.awt.application.appearance", "system" ); ``` -------------------------------- ### Gray Filter Configuration Source: https://www.formdev.com/flatlaf/properties-files Configures a gray filter with brightness, contrast, and alpha values. Brightness and contrast range from -100 to 100, while alpha ranges from 0 (transparent) to 100 (opaque). ```properties Component.grayFilter = 25,-25,100 ``` -------------------------------- ### Enable Transparent Title Bar on macOS Source: https://www.formdev.com/flatlaf/macos Use this client property to enable a transparent title bar for a modern look. Requires Java 11.0.8+ or 8u292+. ```java if( SystemInfo.isMacFullWindowContentSupported ) frame.getRootPane().putClientProperty( "apple.awt.transparentTitleBar", true ); ``` -------------------------------- ### Set Rounded Corners for Text Components using Properties Source: https://www.formdev.com/flatlaf/customizing Set a specific arc value for text components in properties files to achieve rounded corners. ```properties TextComponent.arc = 5 ``` -------------------------------- ### Add Custom Font Styles Source: https://www.formdev.com/flatlaf/typography Add new font styles to FlatLaf.properties and apply them using the 'FlatLaf.styleClass' client property. ```properties [style].xxxl = font: +36 ``` ```java myTitleLabel.putClientProperty( "FlatLaf.styleClass", "xxxl" ); ``` -------------------------------- ### Set Style Class for Typography Source: https://www.formdev.com/flatlaf/typography Assign a style class to a component to apply predefined typography. Recommended for existing components. ```Java myTitleLabel.putClientProperty( "FlatLaf.styleClass", "h1" ); ``` -------------------------------- ### Light/Dark Theme Specific Property Values Source: https://www.formdev.com/flatlaf/properties-files Sets property values that are applied only for light or dark themes, detected using `FlatLaf.isDark()`. Prefixes used are `[light]` and `[dark]`. ```properties [light]Button.background = #fff [dark]Button.background = #000 ``` -------------------------------- ### Set Inner Focus Border Width using Properties Source: https://www.formdev.com/flatlaf/customizing Configure the inner focus border width for components in properties files. This does not increase component size. ```properties Component.innerFocusWidth = 1 Button.innerFocusWidth = 1 ``` -------------------------------- ### Enable Full Window Content on macOS Source: https://www.formdev.com/flatlaf/macos Extends Swing content into the macOS window title bar, allowing interaction and a more integrated appearance. Requires Java 11.0.8+ or 8u292+. ```java if( SystemInfo.isMacFullWindowContentSupported ) { frame.getRootPane().putClientProperty( "apple.awt.fullWindowContent", true ); frame.getRootPane().putClientProperty( "apple.awt.transparentTitleBar", true ); } ``` -------------------------------- ### Maven Dependencies for FlatLaf Native Libraries Source: https://www.formdev.com/flatlaf/native-libraries Specify all FlatLaf native libraries as dependencies in your pom.xml to bundle them with your application. This includes platform-specific libraries for Linux, macOS, and Windows. ```xml ... 3.4 com.formdev flatlaf ${flatlafVersion} com.formdev flatlaf ${flatlafVersion} linux-x86_64 so com.formdev flatlaf ${flatlafVersion} macos-arm64 dylib com.formdev flatlaf ${flatlafVersion} macos-x86_64 dylib com.formdev flatlaf ${flatlafVersion} windows-x86_64 dll com.formdev flatlaf ${flatlafVersion} windows-x86 dll com.formdev flatlaf ${flatlafVersion} windows-arm64 dll ``` -------------------------------- ### Set Arrow Type using Properties Source: https://www.formdev.com/flatlaf/customizing Set the arrow style (chevron or triangle) for components in properties files by defining 'Component.arrowType'. ```properties Component.arrowType = chevron or Component.arrowType = triangle ```