MPS comes with UI components that are similar to their Swing analogs but provide nicer, more featured UI that is also more in line with the rest of the platform. If you want to create a professional, consistent look for your MPS-based tool, use the platform components instead of their Swing equivalents.
Trees
Instead of JTree
use jetbrains.mps.ide.ui.tree.MPSTree
when showing MPS nodes in the tree, or
com.intellij.ui.treeStructure.Tree
otherwise.
Use com.intellij.ui.ColoredListCellRenderer
instead of DefaultListCellRenderer
to show colored labels.
Tables
Use com.intellij.ui.table.JBTable
and com.intellij.ui.ColoredTableCellRenderer
.
Tree tables
See com.intellij.ui.treeStructure.treetable.TreeTable
and com.intellij.ui.CheckboxTreeTable
.
Menus
Instead of using JPopupMenu
directly, use the action
system,
com.intellij.openapi.actionSystem.ActionManager#createActionPopupMenu()
.
Form elements
Use these replacements:
Swing | MPS |
---|---|
JLabel | com.intellij.ui.components.JBLabel |
JComboBox | com.intellij.openapi.ui.ComboBox |
JTextField | com.intellij.ui.components.JBTextField |
JRadioButton | com.intellij.ui.components.JBRadioButton |
JCheckBox | com.intellij.ui.components.JBCheckBox |
Colors
Use com.intellij.ui.JBColor
instead of java.awt.Color
to provide two colors, one for use in light mode and one for
the dark mode.
com.intellij.util.ui.UIUtil
class contains many helpful static methods to obtain theme-specific colors and other settings, such as getLabelTextForeground()
or isUnderDarcula()
.
Message boxes
Instead of JOptionPane.showMessageDialog()
use notification balloons .
Finding examples
These components are used all over MPS and IntelliJ IDEA so it is often enough to find global usages of the classes mentioned above to see them in action. Some of the UI code of MPS and IDEA is inaccessible from within MPS and to look at it you may need to check out MPS sources and open them in IntelliJ IDEA (Community Edition is enough).