Class FlatNativeWindowsLibrary

java.lang.Object
com.formdev.flatlaf.ui.FlatNativeWindowsLibrary

public class FlatNativeWindowsLibrary extends Object
Native methods for Windows.

Note: This is private API. Do not use!

Since:
3.1
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Color
     
    static final int
    DWMWINDOWATTRIBUTE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
    static final int
    DWMWINDOWATTRIBUTE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
    static final int
     
    static final int
     
    static final int
    DWMWINDOWATTRIBUTE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
    static final int
    DWMWINDOWATTRIBUTE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
    static final int
    DWM_WINDOW_CORNER_PREFERENCE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference
    static final int
    DWM_WINDOW_CORNER_PREFERENCE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference
    static final int
    DWM_WINDOW_CORNER_PREFERENCE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference
    static final int
    DWM_WINDOW_CORNER_PREFERENCE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
    static final int
    FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    dwmSetWindowAttributeBOOL(long hwnd, int attribute, boolean value)
    Invokes Win32 API method DwmSetWindowAttribute() with a BOOL attribute value.
    static boolean
    dwmSetWindowAttributeCOLORREF(long hwnd, int attribute, Color color)
    Invokes Win32 API method DwmSetWindowAttribute() with a COLORREF attribute value.
    static boolean
    dwmSetWindowAttributeDWORD(long hwnd, int attribute, int value)
    Invokes Win32 API method DwmSetWindowAttribute() with a DWORD attribute value.
    static long
    getHWND(Window window)
    Gets the Windows window handle (HWND) for the given Swing window.
    static long
    Gets the Windows operating system build number.
    static boolean
    Checks whether native library is loaded/available.
    static boolean
    setWindowCornerPreference(long hwnd, int cornerPreference)
    Sets the rounded corner preference for the window.
    static String[]
    showFileChooser(Window owner, boolean open, String title, String okButtonLabel, String fileNameLabel, String fileName, String folder, String saveAsItem, String defaultFolder, String defaultExtension, int optionsSet, int optionsClear, FlatNativeWindowsLibrary.FileChooserCallback callback, int fileTypeIndex, String[] fileTypes, int[] retFileTypeIndex)
    Shows the Windows system file dialogs IFileOpenDialog or IFileSaveDialog.
    static int
    showMessageBox(long hwndParent, String text, String caption, int type)
    Shows a Windows message box MessageBox.
    static int
    showMessageDialog(long hwndParent, int messageType, String title, String text, int defaultButton, String... buttons)
    Shows a modal Windows message dialog.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DWMWCP_DEFAULT

      public static final int DWMWCP_DEFAULT
      DWM_WINDOW_CORNER_PREFERENCE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference
      See Also:
    • DWMWCP_DONOTROUND

      public static final int DWMWCP_DONOTROUND
      DWM_WINDOW_CORNER_PREFERENCE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference
      See Also:
    • DWMWCP_ROUND

      public static final int DWMWCP_ROUND
      DWM_WINDOW_CORNER_PREFERENCE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference
      See Also:
    • DWMWCP_ROUNDSMALL

      public static final int DWMWCP_ROUNDSMALL
      DWM_WINDOW_CORNER_PREFERENCE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference
      See Also:
    • DWMWA_USE_IMMERSIVE_DARK_MODE

      public static final int DWMWA_USE_IMMERSIVE_DARK_MODE
      DWMWINDOWATTRIBUTE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
      Since:
      3.3
      See Also:
    • DWMWA_BORDER_COLOR

      public static final int DWMWA_BORDER_COLOR
      DWMWINDOWATTRIBUTE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
      Since:
      3.3
      See Also:
    • DWMWA_CAPTION_COLOR

      public static final int DWMWA_CAPTION_COLOR
      DWMWINDOWATTRIBUTE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
      Since:
      3.3
      See Also:
    • DWMWA_TEXT_COLOR

      public static final int DWMWA_TEXT_COLOR
      DWMWINDOWATTRIBUTE see https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
      Since:
      3.3
      See Also:
    • DWMWA_COLOR_DEFAULT

      public static final int DWMWA_COLOR_DEFAULT
      Since:
      3.3
      See Also:
    • DWMWA_COLOR_NONE

      public static final int DWMWA_COLOR_NONE
      Since:
      3.3
      See Also:
    • COLOR_NONE

      public static final Color COLOR_NONE
      Since:
      3.3
    • FOS_OVERWRITEPROMPT

      public static final int FOS_OVERWRITEPROMPT
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
    • FOS_STRICTFILETYPES

      public static final int FOS_STRICTFILETYPES
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
    • FOS_NOCHANGEDIR

      public static final int FOS_NOCHANGEDIR
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
    • FOS_PICKFOLDERS

      public static final int FOS_PICKFOLDERS
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
    • FOS_FORCEFILESYSTEM

      public static final int FOS_FORCEFILESYSTEM
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
    • FOS_ALLNONSTORAGEITEMS

      public static final int FOS_ALLNONSTORAGEITEMS
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
    • FOS_NOVALIDATE

      public static final int FOS_NOVALIDATE
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
    • FOS_ALLOWMULTISELECT

      public static final int FOS_ALLOWMULTISELECT
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
    • FOS_PATHMUSTEXIST

      public static final int FOS_PATHMUSTEXIST
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
    • FOS_FILEMUSTEXIST

      public static final int FOS_FILEMUSTEXIST
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
    • FOS_CREATEPROMPT

      public static final int FOS_CREATEPROMPT
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
    • FOS_SHAREAWARE

      public static final int FOS_SHAREAWARE
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
    • FOS_NOREADONLYRETURN

      public static final int FOS_NOREADONLYRETURN
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
    • FOS_NOTESTFILECREATE

      public static final int FOS_NOTESTFILECREATE
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
    • FOS_HIDEMRUPLACES

      public static final int FOS_HIDEMRUPLACES
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
    • FOS_HIDEPINNEDPLACES

      public static final int FOS_HIDEPINNEDPLACES
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
    • FOS_OKBUTTONNEEDSINTERACTION

      public static final int FOS_OKBUTTONNEEDSINTERACTION
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
    • FOS_DONTADDTORECENT

      public static final int FOS_DONTADDTORECENT
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
    • FOS_FORCESHOWHIDDEN

      public static final int FOS_FORCESHOWHIDDEN
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
    • FOS_DEFAULTNOMINIMODE

      public static final int FOS_DEFAULTNOMINIMODE
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
    • FOS_FORCEPREVIEWPANEON

      public static final int FOS_FORCEPREVIEWPANEON
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
    • FOS_SUPPORTSTREAMABLEITEMS

      public static final int FOS_SUPPORTSTREAMABLEITEMS
      FILEOPENDIALOGOPTIONS see https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
      Since:
      3.7
      See Also:
  • Constructor Details

    • FlatNativeWindowsLibrary

      public FlatNativeWindowsLibrary()
  • Method Details

    • isLoaded

      public static boolean isLoaded()
      Checks whether native library is loaded/available.

      Note: It is required to invoke this method before invoking any other method of this class. Otherwise, the native library may not be loaded.

    • getOSBuildNumber

      public static long getOSBuildNumber()
      Gets the Windows operating system build number.

      Invokes Win32 API method GetVersionEx() and returns OSVERSIONINFO.dwBuildNumber. See https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getversionexa

    • getHWND

      public static long getHWND(Window window)
      Gets the Windows window handle (HWND) for the given Swing window.

      Note that the underlying Windows window must be already created, otherwise this method returns zero. Use following to ensure this:

      if( !window.isDisplayable() )
          window.addNotify();
      
      or invoke this method after packing the window. E.g.
      window.pack();
      long hwnd = getHWND( window );
      
    • setWindowCornerPreference

      public static boolean setWindowCornerPreference(long hwnd, int cornerPreference)
      Sets the rounded corner preference for the window. Allowed values are DWMWCP_DEFAULT, DWMWCP_DONOTROUND, DWMWCP_ROUND and DWMWCP_ROUNDSMALL.

      Invokes Win32 API method DwmSetWindowAttribute(DWMWA_WINDOW_CORNER_PREFERENCE). See https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmsetwindowattribute

      Supported since Windows 11 Build 22000.

    • dwmSetWindowAttributeBOOL

      public static boolean dwmSetWindowAttributeBOOL(long hwnd, int attribute, boolean value)
      Invokes Win32 API method DwmSetWindowAttribute() with a BOOL attribute value. See https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmsetwindowattribute
      Since:
      3.3
    • dwmSetWindowAttributeDWORD

      public static boolean dwmSetWindowAttributeDWORD(long hwnd, int attribute, int value)
      Invokes Win32 API method DwmSetWindowAttribute() with a DWORD attribute value. See https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmsetwindowattribute
      Since:
      3.3
    • dwmSetWindowAttributeCOLORREF

      public static boolean dwmSetWindowAttributeCOLORREF(long hwnd, int attribute, Color color)
      Invokes Win32 API method DwmSetWindowAttribute() with a COLORREF attribute value. See https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmsetwindowattribute

      Supported since Windows 11 Build 22000.

      Since:
      3.3
    • showFileChooser

      public static String[] showFileChooser(Window owner, boolean open, String title, String okButtonLabel, String fileNameLabel, String fileName, String folder, String saveAsItem, String defaultFolder, String defaultExtension, int optionsSet, int optionsClear, FlatNativeWindowsLibrary.FileChooserCallback callback, int fileTypeIndex, String[] fileTypes, int[] retFileTypeIndex)
      Shows the Windows system file dialogs IFileOpenDialog or IFileSaveDialog.

      Note: This method blocks the current thread until the user closes the file dialog. It is highly recommended to invoke it from a new thread to avoid blocking the AWT event dispatching thread.

      Parameters:
      owner - the owner of the file dialog; or null
      open - if true, shows the open dialog; if false, shows the save dialog
      title - text displayed in dialog title; or null
      okButtonLabel - text displayed in default button; or null. Use '&' for mnemonics (e.g. "&Choose"). Use '&&' for '&' character (e.g. "Choose && Quit").
      fileNameLabel - text displayed in front of the filename text field; or null
      fileName - user-editable filename currently shown in the filename field; or null
      folder - current directory shown in the dialog; or null
      saveAsItem - file to be used as the initial entry in a Save As dialog; or null. File name is shown in filename text field, folder is selected in view. To be used for saving files that already exist. For new files use fileName.
      defaultFolder - folder used as a default if there is not a recently used folder value available; or null. Windows somewhere stores default folder on a per-app basis. So this is probably used only once when the app opens a file dialog for first time.
      defaultExtension - default extension to be added to file name in save dialog; or null
      optionsSet - options to set; see FOS_* constants
      optionsClear - options to clear; see FOS_* constants
      callback - approve callback; or null
      fileTypeIndex - the file type that appears as selected (zero-based)
      fileTypes - file types that the dialog can open or save. Pairs of strings are required for each filter. First string is the display name of the filter shown in the combobox (e.g. "Text Files"). Second string is the filter pattern (e.g. "*.txt", "*.exe;*.dll" or "*.*").
      retFileTypeIndex - returns selected file type (zero-based); array must be have one element
      Returns:
      file path(s) that the user selected; an empty array if canceled; or null on failures (no dialog shown)
      Since:
      3.7.1
    • showMessageDialog

      public static int showMessageDialog(long hwndParent, int messageType, String title, String text, int defaultButton, String... buttons)
      Shows a modal Windows message dialog.

      For use in FlatNativeWindowsLibrary.FileChooserCallback only.

      Parameters:
      hwndParent - the parent of the message box
      messageType - type of message being displayed: JOptionPane.ERROR_MESSAGE, JOptionPane.INFORMATION_MESSAGE, JOptionPane.WARNING_MESSAGE, JOptionPane.QUESTION_MESSAGE or JOptionPane.PLAIN_MESSAGE
      title - dialog box title; or null to use title from parent window
      text - message to be displayed
      defaultButton - index of the default button, which can be pressed using ENTER key
      buttons - texts of the buttons. Use '&' for mnemonics (e.g. "&Choose"). Use '&&' for '&' character (e.g. "Choose && Quit").
      Returns:
      index of pressed button; or -1 for ESC key
      Since:
      3.7
    • showMessageBox

      public static int showMessageBox(long hwndParent, String text, String caption, int type)
      Shows a Windows message box MessageBox.

      For use in FlatNativeWindowsLibrary.FileChooserCallback only.

      Parameters:
      hwndParent - the parent of the message box
      text - message to be displayed
      caption - dialog box title
      type - see MessageBox parameter uType
      Returns:
      see MessageBox Return value
      Since:
      3.7