User Interface FAQ
Edit pageLast modified: 23 October 2024tip
Inspecting existing UIUse UI Inspector to locate the underlying Swing component implementation or to inspect an existing UI at runtime.
Useful Classes
Package
com.intellij.ui
Package
com.intellij.util.ui
Colors
Always use JBColor
instead of plain java.awt.Color
(highlighted via inspection Plugin DevKit | Code | Use Darcula aware JBColor). Custom colors must be retrieved via JBColor.namedColor()
set by the current Theme. See Exposing Theme Metadata on how to expose corresponding metadata.
If it's needed to retrieve a color from one place and use it in another, do not just retrieve once and use the retrieved value. Instead, use JBColor.lazy()
and pass in a lambda expression to retrieve the color. This lambda expression needs to be fast and safe enough, as it will be called every time the color is retrieved, for example, for painting. Following this approach ensures that the color will be properly updated if it's changed at the source, for example, due to a theme or scheme change.
Generic UI colors (e.g., for drawing borders) can be accessed via UIUtil
and JBUI
. A number of hardcoded colors is defined in JBColor
, Gray
, and LightColors
ColorUtil
allows tuning existing colors.
Text
UI Guidelines: Data Formats
Use NaturalComparator
for "natural" sorting of items.
StringUtil
contains a number of useful methods for manipulating text for UI usage:
unpluralize()/pluralize()
using English rulesformatDuration()
to format duration: 2 m 3 s 456 msformatFileSize()
to format filesize: 1.23 KBescapeLineBreak()
and related methods to escape special charactersshortenTextWithEllipsis()
andshortenPathWithEllipsis()
to produce abbreviated UI texts ending with '…'quote()
andunquoteString()
to wrap values: Usages of "$value$": 218 found
See Internationalization for information about internationalizing plugins.
See NlsMessages
to produce localized messages.
"Recently Used" Entries
To store and retrieve values for Recently Used entries (e.g., filter values), use RecentsManager
.
Current Theme: Dark or Bright?
To determine the current Theme's style, use JBColor.isBright()
.
Borders and Insets
UI Guidelines: Layout
Always create borders and insets via factory methods from JBUI.Borders
and JBUI.Insets
, which create DPI-aware instances. Using standard DPI-agnostic instances (reported by inspection Plugin DevKit | Code | Use DPI-aware borders and Plugin DevKit | Code | Use DPI-aware insets) can result in UI layout problems.
If you use DPI-aware insets in an empty border (JBUI.Borders.empty()
), then the insets will be updated automatically, for example, if scaling is changed because the IDE Zoom action was performed or for any other reason. If you use the insets elsewhere, you need to manually call JBInsets.update()
in your component's updateUI()
method to update the insets accordingly.
Manipulating Icons
Use IconUtil
to scale/colorize/darken/desaturate existing icons as needed.
note
Something missing?If a topic you are interested in is not covered in the above sections, let us know via the Was this page helpful? feedback form below or other channels.
Please be specific about the topics and reasons for adding them, and leave your email in case we need more details. Thanks for your feedback!
Thanks for your feedback!