Class UIUtil

java.lang.Object
com.intellij.util.ui.DrawUtil
com.intellij.util.ui.UIUtil

public class UIUtil extends DrawUtil
  • Field Details

  • Method Details

    • invokeLaterIfNeeded

      public static void invokeLaterIfNeeded(@NotNull Runnable runnable)
    • getMultiClickInterval

      public static int getMultiClickInterval()
    • applyStyle

      public static void applyStyle(@NotNull UIUtil.ComponentStyle componentStyle, @NotNull Component comp)
    • getGrayFilter

      public static GrayFilter getGrayFilter()
    • hasLeakingAppleListeners

      public static boolean hasLeakingAppleListeners()
    • removeLeakingAppleListeners

      public static void removeLeakingAppleListeners()
    • isClientPropertyTrue

      public static boolean isClientPropertyTrue(Object component, @NotNull Object key)
      Parameters:
      component - a Swing component that may hold a client property value
      key - the client property key
      Returns:
      true if the property of the specified component is set to true
    • getClientProperty

      public static Object getClientProperty(Object component, @NotNull Object key)
      Parameters:
      component - a Swing component that may hold a client property value
      key - the client property key that specifies a return type
      Returns:
      the property value from the specified component or null
    • getClientProperty

      public static <T> T getClientProperty(Object component, @NotNull Key<T> key)
      Parameters:
      component - a Swing component that may hold a client property value
      key - the client property key that specifies a return type
      Returns:
      the property value from the specified component or null
    • putClientProperty

      public static <T> void putClientProperty(@NotNull JComponent component, @NotNull Key<T> key, T value)
    • getHtmlBody

      public static String getHtmlBody(@NotNull String text)
    • isReallyTypedEvent

      public static boolean isReallyTypedEvent(KeyEvent e)
    • getStringY

      public static int getStringY(@NotNull String string, @NotNull Rectangle bounds, @NotNull Graphics2D g)
    • getHighestGlyphHeight

      public static int getHighestGlyphHeight(@NotNull String string, @NotNull Font font, @NotNull Graphics graphics)
      Parameters:
      string - String to examine
      font - Font that is used to render the string
      graphics - Graphics that should be used to render the string
      Returns:
      height of the tallest glyph in a string. If string is empty, returns 0
    • setActionNameAndMnemonic

      public static void setActionNameAndMnemonic(@NotNull String text, @NotNull Action action)
    • assignMnemonic

      public static void assignMnemonic(@NotNull String text, @NotNull Action action)
    • getLabelFont

      public static Font getLabelFont(@NotNull UIUtil.FontSize size)
    • getFont

      @NotNull public static Font getFont(@NotNull UIUtil.FontSize size, @Nullable Font base)
    • getFontSize

      public static float getFontSize(UIUtil.FontSize size)
    • getLabelFontColor

      public static Color getLabelFontColor(UIUtil.FontColor fontColor)
    • getScrollBarWidth

      public static int getScrollBarWidth()
    • getLabelFont

      public static Font getLabelFont()
    • getLabelBackground

      public static Color getLabelBackground()
    • getLabelForeground

      public static Color getLabelForeground()
    • getLabelDisabledForeground

      public static Color getLabelDisabledForeground()
    • getTableHeaderBackground

      public static Color getTableHeaderBackground()
    • getTreeTextForeground

      public static Color getTreeTextForeground()
    • getTreeSelectionBackground

      public static Color getTreeSelectionBackground()
    • getTreeTextBackground

      public static Color getTreeTextBackground()
    • getListSelectionForeground

      public static Color getListSelectionForeground()
    • getFieldForegroundColor

      public static Color getFieldForegroundColor()
    • getTableSelectionBackground

      public static Color getTableSelectionBackground()
    • getActiveTextColor

      public static Color getActiveTextColor()
    • getInactiveTextColor

      public static Color getInactiveTextColor()
    • getSlightlyDarkerColor

      public static Color getSlightlyDarkerColor(Color c)
    • getActiveTextFieldBackgroundColor

      public static Color getActiveTextFieldBackgroundColor()
      Deprecated.
      use com.intellij.util.ui.UIUtil#getTextFieldBackground()
    • getInactiveTextFieldBackgroundColor

      public static Color getInactiveTextFieldBackgroundColor()
    • getTreeFont

      public static Font getTreeFont()
    • getListFont

      public static Font getListFont()
    • getTreeSelectionForeground

      public static Color getTreeSelectionForeground()
    • getTreeForeground

      public static Color getTreeForeground(boolean selected, boolean hasFocus)
    • getTextInactiveTextColor

      public static Color getTextInactiveTextColor()
      Deprecated.
      use com.intellij.util.ui.UIUtil#getInactiveTextColor()
    • installPopupMenuColorAndFonts

      public static void installPopupMenuColorAndFonts(JComponent contentPane)
    • installPopupMenuBorder

      public static void installPopupMenuBorder(JComponent contentPane)
    • getTreeSelectionBorderColor

      public static Color getTreeSelectionBorderColor()
    • getTreeRightChildIndent

      public static int getTreeRightChildIndent()
    • getTreeLeftChildIndent

      public static int getTreeLeftChildIndent()
    • getToolTipBackground

      public static Color getToolTipBackground()
    • getToolTipForeground

      public static Color getToolTipForeground()
    • getComboBoxDisabledForeground

      public static Color getComboBoxDisabledForeground()
    • getComboBoxDisabledBackground

      public static Color getComboBoxDisabledBackground()
    • getButtonSelectColor

      public static Color getButtonSelectColor()
    • getPropertyMaxGutterIconWidth

      public static Integer getPropertyMaxGutterIconWidth(String propertyPrefix)
    • getMenuItemDisabledForeground

      public static Color getMenuItemDisabledForeground()
    • getMenuItemDisabledForegroundObject

      public static Object getMenuItemDisabledForegroundObject()
    • getTabbedPanePaintContentBorder

      public static Object getTabbedPanePaintContentBorder(JComponent c)
    • isMenuCrossMenuMnemonics

      public static boolean isMenuCrossMenuMnemonics()
    • getTableBackground

      public static Color getTableBackground()
    • getTableBackground

      public static Color getTableBackground(boolean isSelected)
    • getTableSelectionForeground

      public static Color getTableSelectionForeground()
    • getTableForeground

      public static Color getTableForeground()
    • getTableForeground

      public static Color getTableForeground(boolean isSelected)
    • getTableGridColor

      public static Color getTableGridColor()
    • getListBackground

      public static Color getListBackground()
    • getListBackground

      public static Color getListBackground(boolean isSelected)
    • getListForeground

      public static Color getListForeground()
    • getListForeground

      public static Color getListForeground(boolean isSelected)
    • getEditorPaneBackground

      public static Color getEditorPaneBackground()
    • getTreeBackground

      public static Color getTreeBackground()
    • getTreeForeground

      public static Color getTreeForeground()
    • getTableFocusCellBackground

      public static Color getTableFocusCellBackground()
    • getListSelectionBackground

      public static Color getListSelectionBackground()
    • getListUnfocusedSelectionBackground

      public static Color getListUnfocusedSelectionBackground()
    • getTreeSelectionBackground

      public static Color getTreeSelectionBackground(boolean focused)
    • getTreeUnfocusedSelectionBackground

      public static Color getTreeUnfocusedSelectionBackground()
    • getTextFieldForeground

      public static Color getTextFieldForeground()
    • getTextFieldBackground

      public static Color getTextFieldBackground()
    • getButtonFont

      public static Font getButtonFont()
    • getToolTipFont

      public static Font getToolTipFont()
    • getTabbedPaneBackground

      public static Color getTabbedPaneBackground()
    • setSliderIsFilled

      public static void setSliderIsFilled(JSlider slider, boolean value)
    • getLabelTextForeground

      public static Color getLabelTextForeground()
    • getControlColor

      public static Color getControlColor()
    • getOptionPaneMessageFont

      public static Font getOptionPaneMessageFont()
    • getMenuFont

      public static Font getMenuFont()
    • getSeparatorForeground

      public static Color getSeparatorForeground()
    • getSeparatorBackground

      public static Color getSeparatorBackground()
    • getSeparatorShadow

      public static Color getSeparatorShadow()
    • getSeparatorHighlight

      public static Color getSeparatorHighlight()
    • getSeparatorColorUnderNimbus

      public static Color getSeparatorColorUnderNimbus()
    • getSeparatorColor

      public static Color getSeparatorColor()
    • getTableFocusCellHighlightBorder

      public static Border getTableFocusCellHighlightBorder()
    • setLineStyleAngled

      public static void setLineStyleAngled(JTree component)
    • getTableFocusCellForeground

      public static Color getTableFocusCellForeground()
    • getPanelBackgound

      public static Color getPanelBackgound()
      Deprecated.
      use com.intellij.util.ui.UIUtil#getPanelBackground() instead
    • getTextFieldBorder

      public static Border getTextFieldBorder()
    • getButtonBorder

      public static Border getButtonBorder()
    • getTreeCollapsedIcon

      public static Icon getTreeCollapsedIcon()
    • getTreeExpandedIcon

      public static Icon getTreeExpandedIcon()
    • getTreeIcon

      public static Icon getTreeIcon(boolean expanded)
    • getTableHeaderCellBorder

      public static Border getTableHeaderCellBorder()
    • getWindowColor

      public static Color getWindowColor()
    • getTextAreaForeground

      public static Color getTextAreaForeground()
    • getOptionPaneBackground

      public static Color getOptionPaneBackground()
    • isUnderAlloyLookAndFeel

      public static boolean isUnderAlloyLookAndFeel()
    • isUnderAlloyIDEALookAndFeel

      public static boolean isUnderAlloyIDEALookAndFeel()
    • isUnderWindowsLookAndFeel

      public static boolean isUnderWindowsLookAndFeel()
    • isUnderWindowsClassicLookAndFeel

      public static boolean isUnderWindowsClassicLookAndFeel()
    • isUnderNimbusLookAndFeel

      public static boolean isUnderNimbusLookAndFeel()
    • isUnderAquaLookAndFeel

      public static boolean isUnderAquaLookAndFeel()
    • isUnderJGoodiesLookAndFeel

      public static boolean isUnderJGoodiesLookAndFeel()
    • isUnderAquaBasedLookAndFeel

      public static boolean isUnderAquaBasedLookAndFeel()
    • isUnderGTKLookAndFeel

      public static boolean isUnderGTKLookAndFeel()
    • getGtkThemeName

      @Nullable public static String getGtkThemeName()
    • isMurrineBasedTheme

      public static boolean isMurrineBasedTheme()
    • shade

      public static Color shade(Color c, double factor, double alphaFactor)
    • mix

      public static Color mix(Color c1, Color c2, double factor)
    • isFullRowSelectionLAF

      public static boolean isFullRowSelectionLAF()
    • isUnderNativeMacLookAndFeel

      public static boolean isUnderNativeMacLookAndFeel()
    • getListCellHPadding

      public static int getListCellHPadding()
    • getListCellVPadding

      public static int getListCellVPadding()
    • getListCellPadding

      public static Insets getListCellPadding()
    • getListViewportPadding

      public static Insets getListViewportPadding()
    • isToUseDottedCellBorder

      public static boolean isToUseDottedCellBorder()
    • isControlKeyDown

      public static boolean isControlKeyDown(MouseEvent mouseEvent)
    • getStandardFontSizes

      public static String[] getStandardFontSizes()
    • isValidFont

      public static boolean isValidFont(@NotNull Font font)
    • setupEnclosingDialogBounds

      public static void setupEnclosingDialogBounds(JComponent component)
    • displayPropertiesToCSS

      public static String displayPropertiesToCSS(Font font, Color fg)
    • appendColor

      public static void appendColor(Color color, StringBuilder sb)
    • applyRenderingHints

      public static void applyRenderingHints(Graphics g)
      This method is intended to use when user settings are not accessible yet. Use it to set up default RenderingHints.
      Parameters:
      g -
    • dispatchAllInvocationEvents

      @TestOnly public static void dispatchAllInvocationEvents()
      See Also:
    • dispatchInvocationEvent

      @TestOnly public static boolean dispatchInvocationEvent()
    • pump

      @TestOnly public static void pump()
      See Also:
    • addParentChangeListener

      public static void addParentChangeListener(@NotNull Component component, @NotNull PropertyChangeListener listener)
    • removeParentChangeListener

      public static void removeParentChangeListener(@NotNull Component component, @NotNull PropertyChangeListener listener)
    • isFocusAncestor

      public static boolean isFocusAncestor(@NotNull JComponent component)
    • isCloseClick

      public static boolean isCloseClick(MouseEvent e)
    • isCloseClick

      public static boolean isCloseClick(MouseEvent e, int effectiveType)
    • isActionClick

      public static boolean isActionClick(MouseEvent e)
    • isActionClick

      public static boolean isActionClick(MouseEvent e, int effectiveType)
    • isActionClick

      public static boolean isActionClick(MouseEvent e, int effectiveType, boolean allowShift)
    • getBgFillColor

      @NotNull public static Color getBgFillColor(@NotNull Component c)
    • findNearestOpaque

      @Nullable public static Component findNearestOpaque(Component c)
    • findParentByCondition

      @Nullable public static Component findParentByCondition(@NotNull Component c, Condition<Component> condition)
    • findParentByClass

      @Deprecated public static <T extends Component> T findParentByClass(@NotNull Component c, Class<T> cls)
      Deprecated.
    • getCssFontDeclaration

      public static String getCssFontDeclaration(@NotNull Font font)
    • getCssFontDeclaration

      public static String getCssFontDeclaration(@NotNull Font font, @Nullable Color fgColor, @Nullable Color linkColor, @Nullable String liImg)
    • isWinLafOnVista

      public static boolean isWinLafOnVista()
    • isStandardMenuLAF

      public static boolean isStandardMenuLAF()
    • getFocusedFillColor

      public static Color getFocusedFillColor()
    • getFocusedBoundsColor

      public static Color getFocusedBoundsColor()
    • getBoundsColor

      public static Color getBoundsColor()
    • getBoundsColor

      public static Color getBoundsColor(boolean focused)
    • toAlpha

      public static Color toAlpha(Color color, int alpha)
    • isFocusable

      public static boolean isFocusable(JComponent component)
      Parameters:
      component - to check whether it can be focused or not
      Returns:
      true if component is not null and can be focused
      See Also:
      • Component.isRequestFocusAccepted(boolean, boolean, sun.awt.CausedFocusEvent.Cause)
    • requestFocus

      public static void requestFocus(@NotNull JComponent c)
    • dispose

      public static void dispose(Component c)
    • findUltimateParent

      @Nullable public static Component findUltimateParent(Component c)
    • getHeaderActiveColor

      public static Color getHeaderActiveColor()
    • getHeaderInactiveColor

      public static Color getHeaderInactiveColor()
    • getBorderColor

      public static Color getBorderColor()
      Deprecated.
    • getTitledBorderFont

      public static Font getTitledBorderFont()
    • getBorderInactiveColor

      public static Color getBorderInactiveColor()
      Deprecated.
      use getBorderColor instead
    • getBorderActiveColor

      public static Color getBorderActiveColor()
      Deprecated.
      use getBorderColor instead
    • getBorderSeparatorColor

      public static Color getBorderSeparatorColor()
      Deprecated.
      use getBorderColor instead
    • getHTMLEditorKit

      public static HTMLEditorKit getHTMLEditorKit()
    • getHTMLEditorKit

      public static HTMLEditorKit getHTMLEditorKit(boolean noGapsBetweenParagraphs)
    • getCenterPoint

      public static Point getCenterPoint(Dimension container, Dimension child)
    • getCenterPoint

      public static Point getCenterPoint(Rectangle container, Dimension child)
    • toHtml

      public static String toHtml(String html)
    • toHtml

      @NonNls public static String toHtml(String html, int hPadding)
    • addPadding

      public static String addPadding(String html, int hPadding)
    • convertSpace2Nbsp

      @NotNull public static String convertSpace2Nbsp(@NotNull String html)
    • isFocusProxy

      public static boolean isFocusProxy(@Nullable Component c)
    • setFocusProxy

      public static void setFocusProxy(JComponent c, boolean isProxy)
    • maybeInstall

      public static void maybeInstall(InputMap map, String action, KeyStroke stroke)
    • changeBackGround

      public static void changeBackGround(Component component, Color background)
      Avoid blinking while changing background.
      Parameters:
      component - component.
      background - new background.
    • getSystemLookAndFeelClassName

      public static String getSystemLookAndFeelClassName()
    • initDefaultLAF

      public static void initDefaultLAF()
    • initSystemFontData

      public static void initSystemFontData()
    • getSystemFontData

      @Nullable public static Pair<String,Integer> getSystemFontData()
    • addKeyboardShortcut

      public static void addKeyboardShortcut(JComponent target, AbstractButton button, KeyStroke keyStroke)
    • installComboBoxCopyAction

      public static void installComboBoxCopyAction(JComboBox comboBox)
    • getComboBoxPopup

      @Nullable public static ComboPopup getComboBoxPopup(@NotNull JComboBox comboBox)
    • fixFormattedField

      public static void fixFormattedField(JFormattedTextField field)
    • isPrinting

      public static boolean isPrinting(Graphics g)
    • getSelectedButton

      public static int getSelectedButton(ButtonGroup group)
    • setSelectedButton

      public static void setSelectedButton(ButtonGroup group, int index)
    • isSelectionButtonDown

      public static boolean isSelectionButtonDown(MouseEvent e)
    • setComboBoxEditorBounds

      public static void setComboBoxEditorBounds(int x, int y, int width, int height, JComponent editor)
    • fixComboBoxHeight

      public static int fixComboBoxHeight(int height)
    • isDescendingFrom

      public static boolean isDescendingFrom(@Nullable Component child, @NotNull Component parent)
      The main difference from javax.swing.SwingUtilities#isDescendingFrom(Component, Component) is that this method uses getInvoker() instead of getParent() when it meets JPopupMenu
      Parameters:
      child - child component
      parent - parent component
      Returns:
      true if parent if a top parent of child, false otherwise
      See Also:
    • getParentOfType

      @Nullable public static <T> T getParentOfType(@NotNull Class<? extends T> type, Component component)
      Searches above in the component hierarchy starting from the specified component. Note that the initial component is also checked.
      Parameters:
      type - expected class
      component - initial component
      Returns:
      a component of the specified type, or null if the search is failed
      See Also:
    • scrollListToVisibleIfNeeded

      public static void scrollListToVisibleIfNeeded(@NotNull JList list)
    • findComponentOfType

      @Nullable public static <T extends JComponent> T findComponentOfType(JComponent parent, Class<T> cls)
    • findComponentsOfType

      public static <T extends JComponent> List<T> findComponentsOfType(JComponent parent, Class<T> cls)
    • getRootPane

      @Nullable public static JRootPane getRootPane(Component c)
    • setFutureRootPane

      public static void setFutureRootPane(JComponent c, JRootPane pane)
    • isMeaninglessFocusOwner

      public static boolean isMeaninglessFocusOwner(@Nullable Component c)
    • createNamedTimer

      @NotNull public static Timer createNamedTimer(@NonNls @NotNull String name, int delay, @NotNull ActionListener listener)
    • createNamedTimer

      @NotNull public static Timer createNamedTimer(@NonNls @NotNull String name, int delay)
    • isDialogRootPane

      public static boolean isDialogRootPane(JRootPane rootPane)
    • setNotOpaqueRecursively

      public static void setNotOpaqueRecursively(@NotNull Component component)
    • setBackgroundRecursively

      public static void setBackgroundRecursively(@NotNull Component component, @NotNull Color bg)
    • addInsets

      public static void addInsets(@NotNull JComponent component, int top, int left, int bottom, int right)
      Adds an empty border with the specified insets to the specified component. If the component already has a border it will be preserved.
      Parameters:
      component - the component to which border added
      top - the inset from the top
      left - the inset from the left
      bottom - the inset from the bottom
      right - the inset from the right
    • addInsets

      public static void addInsets(@NotNull JComponent component, @NotNull Insets insets)
      Adds an empty border with the specified insets to the specified component. If the component already has a border it will be preserved.
      Parameters:
      component - the component to which border added
      insets - the top, left, bottom, and right insets
    • adjustWindowToMinimumSize

      public static void adjustWindowToMinimumSize(Window window)
    • getColorAt

      @Nullable public static Color getColorAt(Icon icon, int x, int y)
    • addBorder

      public static void addBorder(JComponent component, Border border)
      Adds the specified border to the specified component. If the component already has a border it will be preserved. If component or border is not specified nothing happens.
      Parameters:
      component - the component to which border added
      border - the border to add to the component
    • getDecoratedRowColor

      public static Color getDecoratedRowColor()
    • getLocationOnScreen

      @Nullable public static Point getLocationOnScreen(@NotNull JComponent component)
    • getActiveWindow

      @NotNull public static Window getActiveWindow()
    • suppressFocusStealing

      public static void suppressFocusStealing(Window window)
    • setAutoRequestFocus

      public static void setAutoRequestFocus(Window onWindow, boolean set)
    • getDebugText

      public static String getDebugText(Component c)
    • isAncestor

      public static boolean isAncestor(@NotNull Component ancestor, @Nullable Component descendant)
    • getRealFontFamily

      public static String getRealFontFamily(String genericFontFamily)
    • configureNumericFormattedTextField

      public static void configureNumericFormattedTextField(@NotNull JFormattedTextField textField)
      It is your responsibility to set correct horizontal align (left in case of UI Designer)
    • getWindow

      public static Window getWindow(Component component)
      Returns the first window ancestor of the component. Note that this method returns the component itself if it is a window.
      Parameters:
      component - the component used to find corresponding window
      Returns:
      the first window ancestor of the component; or null if the component is not a window and is not contained inside a window
    • toFront

      public static void toFront(Window window)
      Places the specified window at the top of the stacking order and shows it in front of any other windows. If the window is iconified it will be shown anyway.
      Parameters:
      window - the window to activate
    • getDebugImage

      public static Image getDebugImage(Component component)
    • hasScrollPane

      public static boolean hasScrollPane(@NotNull Component component)
      Indicates whether the specified component is scrollable or it contains a scrollable content.
    • hasComponentOfType

      public static boolean hasComponentOfType(Component component, Class<?>... types)
      Indicates whether the specified component is instance of one of the specified types or it contains an instance of one of the specified types.
    • setColumns

      public static void setColumns(JTextComponent textComponent, int columns)
    • getPreferredFocusedComponent

      public static JComponent getPreferredFocusedComponent(Container container)
      Returns the first focusable component in the specified container. This method returns null if container is null, or if focus traversal policy cannot be determined, or if found focusable component is not a JComponent.
      Parameters:
      container - a container whose first focusable component is to be returned
      Returns:
      the first focusable component or null if it cannot be found
    • getComponentStyle

      public static UIUtil.ComponentStyle getComponentStyle(Component component)
      Calculates a component style from the corresponding client property. The key "JComponent.sizeVariant" is used by Apple's Linvalid input: '&F' to scale components.
      Parameters:
      component - a component to process
      Returns:
      a component style of the specified component
    • getLcdContrastValue

      public static int getLcdContrastValue()