Client Properties
Component client properties can be used to change some behavior of Swing components in FlatLaf. In comparison to UI defaults, which are global and affect all components, client properties can be set on individual components. See JComponent.putClientProperty().
Examples:
myButton.putClientProperty( "JButton.buttonType", "roundRect" ); myScrollPane.putClientProperty( "JScrollBar.showButtons", true );
This documentation uses strings for keys and some values. If you prefer using constants, have a look at interface FlatClientProperties:
myButton.putClientProperty( FlatClientProperties.BUTTON_TYPE, FlatClientProperties.BUTTON_TYPE_ROUND_RECT ); myScrollPane.putClientProperty( FlatClientProperties.SCROLL_BAR_SHOW_BUTTONS, true );
An alternative to using these client properties is to use components from FlatLaf Extras library (see package com.formdev.flatlaf.extras.components), which extend standard Swing components and provide getter and setter methods for these client properties.
JButton / JToggleButton
Key | Description | Component | Value type |
---|---|---|---|
JButton.buttonType | Specifies type of button. Allowed Values:
|
JButton and JToggleButton |
|
JButton.squareSize | Specifies whether the button preferred size will be made square (quadratically). | JButton and JToggleButton |
Boolean |
JCheckBox
Key | Description | Component | Value type |
---|---|---|---|
JButton.selectedState | Specifies selected state of a checkbox. Allowed Values:
|
JCheckBox |
|
JComponent
Key | Description | Component | Value type |
---|---|---|---|
FlatLaf.style since v2 |
Specifies the style of a component as String in CSS syntax ("key1: value1; key2: value2; ...")
or as
The keys are the same as used in UI defaults, but without component type prefix.
E.g. for UI default The syntax of the CSS values is the same as used in FlatLaf properties files, but some features are not supported (e.g. variables). When using a map, the values are not parsed from a string. They must be binary. |
JComponent |
String or Map<String, Object> |
FlatLaf.styleClass since v2 |
Specifies the style class(es) of a component as String (single class or multiple classes separated by space characters)
or as
The style rules must be defined in UI defaults either as strings (in CSS syntax)
or as |
JComponent |
String , String[] or List<String> |
[style]Button.primary = borderColor: #08f; background: #08f; foreground: #fff [style].secondary = borderColor: #0f8; background: #0f8 or in Java code: UIManager.put( "[style]Button.primary", "borderColor: #08f; background: #08f; foreground: #fff" ); UIManager.put( "[style].secondary", "borderColor: #0f8; background: #0f8" ); The rule "Button.primary" can be applied to buttons only. The rule ".secondary" can be applied to any component.
To have similar behavior as in CSS, first the rule without type is applied,
then the rule with type.
E.g. setting style class to "foo" on a |
|||
JComponent.minimumWidth | Specifies minimum width of a component. | JButton , JToggleButton , JComboBox , JSpinner and JTextComponent |
Integer |
JComponent.minimumHeight | Specifies minimum height of a component. | JButton and JToggleButton |
Integer |
JComponent.roundRect | Paint the component with round edges. | JComboBox , JSpinner , JTextField , JFormattedTextField and JPasswordField |
Boolean |
JComponent.outline | Specifies the outline color of the component border. Allowed Values:
|
JButton , JComboBox , JFormattedTextField , JPasswordField , JScrollPane , JSpinner , JTextField and JToggleButton |
|
JComponent.focusOwner | Specifies a callback that is invoked to check whether a component is permanent focus owner. Used to paint focus indicators. May be useful in special cases for custom components. | JComponent |
Predicate <JComponent> |
Use a myComponent.putClientProperty( "JComponent.focusOwner", (Predicate<JComponent>) c -> { return ...; // check here } ); |
|||
JComponent.titleBarCaption since v2.5 | Specifies whether a component shown in a window title bar area should behave as caption (left-click allows moving window, right-click shows window system menu). The caption component does not receive mouse pressed/released/clicked/dragged events, but it gets mouse entered/exited/moved events. | JComponent |
Boolean or Function <Point, Boolean> |
Since FlatLaf 3.4, this client property also supports using a function that can check whether a given location in the component should behave as caption. Useful for components that do not use mouse input on whole component bounds. myComponent.putClientProperty( "JComponent.titleBarCaption", (Function<Point, Boolean>) pt -> { // parameter pt contains mouse location (in myComponent coordinates) // return true if the component is not interested in mouse input at the given location // return false if the component wants process mouse input at the given location // return null if the component children should be checked return ...; // check here } ); Warning:
|
JPanel
Key | Description | Component | Value type |
---|---|---|---|
FlatLaf.fullWindowContent.buttonsPlaceholder since v3.4 |
Marks the panel as placeholder for the iconfify/maximize/close buttons in fullWindowContent mode. See client property FlatLaf.fullWindowContent. | JPanel |
String |
If fullWindowContent mode is enabled, the preferred size of the panel is equal
to the size of the iconfify/maximize/close buttons. Otherwise is is You're responsible to layout that panel at the top-left or top-right corner, depending on platform, where the iconfify/maximize/close buttons are located. Syntax of the value string is: The string must start with Optionally, you can append following options to the value string (separated by space characters):
Example for adding placeholder to top-left corner on macOS: 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 ); Or add placeholder as first item to the tool bar: 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 ); If a tabbed pane is located at the top, you can add the placeholder as leading component to that tabbed pane: JPanel placeholder = new JPanel(); placeholder.putClientProperty( FlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_PLACEHOLDER, "mac" ); tabbedPane.putClientProperty( FlatClientProperties.TABBED_PANE_LEADING_COMPONENT, placeholder ); |
Popup
Key | Description | Component | Value type |
---|---|---|---|
Popup.borderCornerRadius since v3.1 |
Specifies the popup border corner radius if the component is shown in a popup or if the component is the owner of another component that is shown in a popup. Note that this is not available on all platforms since it requires special support. Supported platforms:
|
JComponent |
|
Popup.roundedBorderWidth since v3.3 |
Specifies the popup rounded border width if the component is shown in a popup or if the component is the owner of another component that is shown in a popup. Only used if popup uses rounded border. Note that this is not available on all platforms since it requires special support. Supported platforms:
|
JComponent |
|
Popup.dropShadowPainted | Specifies whether a drop shadow is painted if the component is shown in a popup or if the component is the owner of another component that is shown in a popup. | JComponent |
Boolean |
Popup.forceHeavyWeight | Specifies whether a heavy weight window should be used if the component is shown in a popup or if the component is the owner of another component that is shown in a popup. | JComponent |
Boolean |
JProgressBar
Key | Description | Component | Value type |
---|---|---|---|
JProgressBar.largeHeight | Specifies whether the progress bar has always the larger height even if no string is painted. | JProgressBar |
Boolean |
JProgressBar.square | Specifies whether the progress bar is paint with square edges. | JProgressBar |
Boolean |
JRootPane
Key | Description | Component | Value type |
---|---|---|---|
JRootPane.useWindowDecorations since v1.1.1 |
Specifies whether FlatLaf native window decorations should be used
for JFrame or JDialog .
Setting this enables/disables using FlatLaf native window decorations
for the window that contains the root pane.
This client property has lower priority than system property
flatlaf.useWindowDecorations , but higher priority
than UI default TitlePane.useWindowDecorations .(requires Windows 10/11) |
JRootPane |
Boolean |
JRootPane.menuBarEmbedded | Specifies whether the menu bar is embedded into the window title pane
if window decorations are enabled.
Setting this enables/disables embedding
for the window that contains the root pane.
This client property has lower priority than system property
flatlaf.menuBarEmbedded , but higher priority
than UI default TitlePane.menuBarEmbedded .(requires Windows 10/11) |
JRootPane |
Boolean |
FlatLaf.fullWindowContent since v3.4 | Specifies whether the content pane (and the glass pane) should be extended
into the window title bar area
(requires enabled window decorations). Default is
On macOS, use client property
Setting this enables/disables full window content
for the
If
The user can left-click-and-drag on the title bar area to move the window,
except when clicking on a component that processes mouse events (e.g. buttons or menus). |
JRootPane |
Boolean |
FlatLaf.fullWindowContent.buttonsBounds since v3.4 | Contains the current bounds of the iconfify/maximize/close buttons
(in root pane coordinates) if fullWindowContent mode is enabled.
Otherwise its value is Note: Do not set this client property. It is set by FlatLaf. |
JRootPane |
Rectangle |
JRootPane.titleBarShowIcon since v2 |
Specifies whether the window icon should be shown in the window title bar
(requires enabled window decorations). Default is UI property TitlePane.showIcon .Setting this shows/hides the windows icon for the JFrame or JDialog that contains the root pane.
This client property has higher priority than UI default TitlePane.showIcon .(requires Windows 10/11) |
JRootPane |
Boolean |
JRootPane.titleBarShowTitle since v3 |
Specifies whether the window title should be shown in the window title bar
(requires enabled window decorations). Default is true .Setting this shows/hides the windows title for the JFrame or JDialog that contains the root pane.(requires Windows 10/11) |
JRootPane |
Boolean |
JRootPane.titleBarShowIconify since v3 |
Specifies whether the "iconify" button should be shown in the window title bar
(requires enabled window decorations). Default is true .Setting this shows/hides the "iconify" button for the JFrame or JDialog that contains the root pane.(requires Windows 10/11) |
JRootPane |
Boolean |
JRootPane.titleBarShowMaximize since v3 |
Specifies whether the "maximize/restore" button should be shown in the window title bar
(requires enabled window decorations). Default is true .Setting this shows/hides the "maximize/restore" button for the JFrame or JDialog that contains the root pane.(requires Windows 10/11) |
JRootPane |
Boolean |
JRootPane.titleBarShowClose since v3 |
Specifies whether the "close" button should be shown in the window title bar
(requires enabled window decorations). Default is true .Setting this shows/hides the "close" button for the JFrame or JDialog that contains the root pane.(requires Windows 10/11) |
JRootPane |
Boolean |
JRootPane.titleBarBackground since v1.1.2 |
Background color of window title bar (requires enabled window decorations). (requires Windows 10/11) |
JRootPane |
Color |
JRootPane.titleBarForeground since v1.1.2 |
Foreground color of window title bar (requires enabled window decorations). (requires Windows 10/11) |
JRootPane |
Color |
JRootPane.titleBarHeight since v3.5.2 |
Specifies the preferred height of title bar (requires enabled window decorations). (requires Windows 10/11) |
JRootPane |
Integer |
JRootPane.glassPaneFullHeight since v3.1 |
Specifies whether the glass pane should have full height and overlap the title bar,
if FlatLaf window decorations are enabled. Default is false .(requires Windows 10/11) |
JRootPane |
Boolean |
Window.style since v3.2 |
Specifies the style of the window title bar.
Besides the default title bar style, you can use a Utility-style title bar,
which is smaller than the default title bar.
On Windows 10/11, this requires FlatLaf window decorations.
On macOS, Java supports this out of the box.
Note that this client property must be set before the window becomes displayable.
Otherwise, an Allowed Values:
|
JRootPane |
|
JScrollBar / JScrollPane
Key | Description | Component | Value type |
---|---|---|---|
JScrollBar.showButtons | Specifies whether the decrease/increase arrow buttons of a scrollbar are shown. | JScrollBar or JScrollPane |
Boolean |
JScrollPane.smoothScrolling | Specifies whether the scroll pane uses smooth scrolling. | JScrollPane |
Boolean |
JSplitPane
Key | Description | Component | Value type |
---|---|---|---|
JSplitPane.expandableSide since v2.2 |
Specifies what side of the spilt pane is allowed to expand
via one-touch expanding arrow buttons.
Requires that one-touch expanding is enabled with
Allowed Values:
|
JSplitPane |
|
JTabbedPane
Key | Description | Component | Value type |
---|---|---|---|
JTabbedPane.tabType since v2 |
Specifies type of the selected tab. Allowed Values:
|
JTabbedPane |
|
JTabbedPane.showTabSeparators | Specifies whether separators are shown between tabs. | JTabbedPane |
Boolean |
JTabbedPane.showContentSeparator | Specifies whether the separator between tabs area and content area should be shown. | JTabbedPane |
Boolean |
JTabbedPane.hasFullBorder | Specifies whether a full border is painted around a tabbed pane. | JTabbedPane |
Boolean |
JTabbedPane.hideTabAreaWithOneTab | Specifies whether the tab area should be hidden if it contains only one tab. | JTabbedPane |
Boolean |
JTabbedPane.minimumTabWidth | Specifies the minimum width of a tab. | JTabbedPane or tab content components |
Integer |
JTabbedPane.maximumTabWidth | Specifies the maximum width of a tab.
Applied only if tab does not have a custom tab component
(see |
JTabbedPane or tab content components |
Integer |
JTabbedPane.tabHeight | Specifies the minimum height of a tab. | JTabbedPane |
Integer |
JTabbedPane.tabInsets | Specifies the insets of a tab. | JTabbedPane or tab content components |
Insets |
JTabbedPane.tabAreaInsets | Specifies the insets of the tab area. | JTabbedPane |
Insets |
JTabbedPane.tabClosable | Specifies whether tabs are closable.
If set to
Note that you have to specify a callback (see client property |
JTabbedPane or tab content components |
Boolean |
JTabbedPane.tabCloseToolTipText | Specifies the tooltip text used for tab close buttons. | JTabbedPane or tab content components |
String |
JTabbedPane.tabCloseCallback | Specifies the callback that is invoked when a tab close button is clicked. The callback is responsible for closing the tab.
Either use a |
JTabbedPane or tab content components |
IntConsumer or BiConsumer <JTabbedPane, Integer> |
myTabbedPane.putClientProperty( "JTabbedPane.tabCloseCallback", (IntConsumer) tabIndex -> { // close tab here } ); Or use a myTabbedPane.putClientProperty( "JTabbedPane.tabCloseCallback", (BiConsumer<JTabbedPane, Integer>) (tabbedPane, tabIndex) -> { // close tab here } ); If you need to check whether a modifier key (e.g. Alt or Shift) was pressed
while the user clicked the tab close button, use AWTEvent e = EventQueue.getCurrentEvent(); boolean shift = (e instanceof MouseEvent) ? ((MouseEvent)e).isShiftDown() : false; |
|||
JTabbedPane.tabsPopupPolicy | Specifies the display policy for the "more tabs" button, which shows a popup menu with the (partly) hidden tabs. Allowed Values:
|
JTabbedPane |
|
JTabbedPane.scrollButtonsPolicy | Specifies the display policy for the forward/backward scroll arrow buttons. Allowed Values:
|
JTabbedPane |
|
JTabbedPane.scrollButtonsPlacement | Specifies the placement of the forward/backward scroll arrow buttons. Allowed Values:
|
JTabbedPane |
|
JTabbedPane.tabAreaAlignment | Specifies the alignment of the tab area. Allowed Values:
|
JTabbedPane |
|
JTabbedPane.tabAlignment | Specifies the horizontal alignment of the tab title and icon. Allowed Values:
|
JTabbedPane or tab content components |
|
JTabbedPane.tabWidthMode | Specifies how the tabs should be sized. Allowed Values:
|
JTabbedPane |
|
JTabbedPane.tabIconPlacement | Specifies the tab icon placement (relative to tab title). Allowed Values:
|
JTabbedPane |
|
JTabbedPane.tabRotation since v3.3 |
Specifies the rotation of the tabs (title, icon, etc.). Allowed Values:
|
JTabbedPane |
|
JTabbedPane.leadingComponent | Specifies a component that will be placed at the leading edge of the tabs area. For top and bottom tab placement, the laid out component size will be the preferred component width and the tab area height. For left and right tab placement, the laid out component size will be the tab area width and the preferred component height. |
JTabbedPane |
Component |
JTabbedPane.trailingComponent | Specifies a component that will be placed at the trailing edge of the tabs area. For top and bottom tab placement, the laid out component size will be the available horizontal space (minimum is preferred component width) and the tab area height. For left and right tab placement, the laid out component size will be the tab area width and the available vertical space (minimum is preferred component height). |
JTabbedPane |
Component |
JTextField
Key | Description | Component | Value type |
---|---|---|---|
JTextField.selectAllOnFocusPolicy | Specifies whether all text is selected when the text component gains focus. Allowed Values:
|
JTextField (and subclasses) |
|
JTextField.placeholderText | Placeholder text that is only painted if the text field is empty. | JTextField (and subclasses) or JComboBox |
String |
JTextField.padding since v1.4 |
Specifies the padding of the text. This changes the location and size of the text view within the component bounds, but does not affect the size of the component. | JTextField (and subclasses) |
Insets |
JTextField.leadingIcon since v2 |
Specifies an icon that will be placed at the leading edge of the text field. | JTextField (and subclasses) |
Icon |
JTextField.trailingIcon since v2 |
Specifies an icon that will be placed at the trailing edge of the text field. | JTextField (and subclasses) |
Icon |
JTextField.leadingComponent since v2 |
Specifies a component that will be placed at the leading edge of the text field. | JTextField (and subclasses) |
JComponent |
The component will be positioned inside and aligned to the visible text field border. There is no gap between the visible border and the component. The laid out component size will be the preferred component width and the inner text field height.
The component should be not opaque because the text field border is painted
slightly inside the usually visible border in some cases.
E.g. when focused (in some themes) or when an outline color is specified
(see client property The component is prepared in the following way:
Because text fields use the text cursor by default and the cursor is inherited by child components,
it may be necessary to explicitly set component cursor if you e.g. need the default arrow cursor.
Styling is used to modify insets/margins and appearance of buttons and toolbars
so that they fit nicely into the text field and do not increase text field height.
See styles |
|||
JTextField.trailingComponent since v2 |
Specifies a component that will be placed at the trailing edge of the text field.
See |
JTextField (and subclasses) |
JComponent |
JTextField.showClearButton since v2 |
Specifies whether a "clear" (or "cancel") button is shown on the trailing side
if the text field is not empty, editable and enabled. Default is false . |
JTextField (and subclasses) |
Boolean |
JTextField.clearCallback since v2 |
Specifies the callback that is invoked when a "clear" (or "cancel") button is clicked. If a callback is specified than it is responsible for clearing the text field. Without callback, the text field clears itself. | JTextField (and subclasses) |
Runnable or Consumer <JTextComponent> |
Either use a myTextField.putClientProperty( "JTextField.clearCallback", (Runnable) () -> { // clear field here or cancel search } ); Or use a myTextField.putClientProperty( "JTextField.clearCallback", (Consumer<JTextComponent>) textField -> { // clear field here or cancel search } ); |
|||
JToggleButton
Key | Description | Component | Value type |
---|---|---|---|
JToggleButton.tab.underlinePlacement since v2.3 | Placement of underline if toggle button type is Allowed Values:
|
JToggleButton |
|
JToggleButton.tab.underlineHeight | Height of underline if toggle button type is "tab" (see client property JButton.buttonType ). |
JToggleButton |
Integer |
JToggleButton.tab.underlineColor | Color of underline if toggle button type is "tab" (see client property JButton.buttonType ). |
JToggleButton |
Color |
JToggleButton.tab.selectedBackground | Background color if selected and toggle button type is "tab" (see client property JButton.buttonType ). |
JToggleButton |
Color |
JTree
Key | Description | Component | Value type |
---|---|---|---|
JTree.wideSelection | Override if a tree shows a wide selection. Default is true . |
JTree |
Boolean |
JTree.paintSelection | Specifies whether tree item selection is painted. Default is true .
If set to false , then the tree cell renderer is responsible for painting selection. |
JTree |
Boolean |
macOS
Key | Description | Component | Value type |
---|---|---|---|
FlatLaf.macOS.windowButtonsSpacing since v3.4 | Specifies the spacing around the macOS window close/minimize/zoom buttons. Useful if full window content is enabled. (requires macOS 10.14+ for "medium" spacing and macOS 11+ for "large" spacing, requires Java 17+) Allowed Values:
|
JRootPane |
|