JComponent () { // JTextField component with browse button TextFieldWithBrowseButton tfbb = new TextFieldWithBrowseButton(e -> System.out.println("JTextField browse button pressed")); new ComponentValidator(getDisposable()).withValidator(() -> tfbb.getText().length() < 50 ? new ValidationInfo(tfbb.getText() + " is too short. Enter at least 50 symbols", tfbb) : null). withOutlineProvider(ComponentValidator.CWBB_PROVIDER). andStartOnFocusLost(). installOn(tfbb); tfbb.getTextField().getDocument().addDocumentListener(new DocumentAdapter() { @Override protected void textChanged(@NotNull DocumentEvent e) { ComponentValidator.getInstance(tfbb).ifPresent(ComponentValidator::revalidate); } }); // EditorTextField component with browse button EditorTextField editor = new EditorTextField(); ComponentWithBrowseButton<EditorTextField> etfbb = new ComponentWithBrowseButton<>(editor, e -> System.out.println("JTextField browse button pressed")); new ComponentValidator(getDisposable()).withValidator(() -> { try { //noinspection ResultOfObjectAllocationIgnored new URL(etfbb.getChildComponent().getDocument().getText()); return null; } catch (MalformedURLException mex) { return new ValidationInfo("Enter a valid URL", etfbb); } }).withOutlineProvider(ComponentValidator.CWBB_PROVIDER).andStartOnFocusLost().installOn(etfbb); etfbb.getChildComponent().getDocument().addDocumentListener(new DocumentListener() { @Override public void documentChanged(@NotNull com.intellij.openapi.editor.event.DocumentEvent event) { ComponentValidator.getInstance(etfbb).ifPresent(ComponentValidator::revalidate); } }); // EditorComboBoxEditor ComboBox<String> comboBox = new ComboBox<>(STRING_VALUES); EditorComboBoxEditor cbEditor = new EditorComboBoxEditor(project, FileTypes.PLAIN_TEXT); comboBox.setEditor(cbEditor); comboBox.addActionListener(l -> ComponentValidator.getInstance(comboBox).ifPresent(ComponentValidator::revalidate)); new ComponentValidator(getDisposable()) .withValidator(() -> comboBox.getSelectedIndex() % 2 == 0 ? new ValidationInfo("Can't select odd items", comboBox) : null) .installOn(comboBox); // Extendable ComboBox ExtendableTextComponent.Extension browseExtension = ExtendableTextComponent.Extension.create(AllIcons.General.OpenDisk, AllIcons.General.OpenDiskHover, "Open file", () -> System.out.println("Browse file clicked")); ComboBox<String> eComboBox = new ComboBox<>(STRING_VALUES); ComponentValidator eComboBoxValidator = new ComponentValidator(getDisposable()).withValidator(() -> { Object item = eComboBox.getEditor().getItem(); String text = item == null ? "" : item.toString(); if (text.isBlank()) return new ValidationInfo("Blank lines are not supported", eComboBox); if (text.contains("e")) return new ValidationInfo("Letter 'e' is prohibited", eComboBox); return null; // text is valid }); eComboBoxValidator.installOn(eComboBox); eComboBoxValidator.revalidate(); // needed because text is already set eComboBox.addActionListener(event -> eComboBoxValidator.revalidate()); eComboBox.setEditable(true); eComboBox.setEditor(new BasicComboBoxEditor(){ @Override protected JTextField createEditorComponent() { ExtendableTextField ecbEditor = new ExtendableTextField(); ecbEditor.addExtension(browseExtension); ecbEditor.setBorder(null); ecbEditor.getDocument().addDocumentListener(new DocumentAdapter() { @Override protected void textChanged(@NotNull DocumentEvent event) { eComboBoxValidator.revalidate(); } }); return ecbEditor; } }); ComboBox<String> animatedIconComboBox = new ComboBox<>(); animatedIconComboBox.setEditable(true); animatedIconComboBox.setEditor(new BasicComboBoxEditor(){ @Override protected JTextField createEditorComponent() { ExtendableTextField cbEditor = new ExtendableTextField(); cbEditor.addExtension(new ExtendableTextComponent.Extension() { private final Icon icon = new AnimatedIcon.FS(); @Override public Icon getIcon(boolean hovered) { return !hovered ? icon : AllIcons.Process.FS.Step_passive; } @Override public String getTooltip() { return "Refresh"; } }); cbEditor.setEditable(false); cbEditor.setBorder(null); return cbEditor; } }); // Panels factory return UI.PanelFactory.grid(). add(UI.PanelFactory.panel(tfbb). withLabel("Default directory:").withComment("Preselected in \"Open ...\" and \"New | Project\" dialogs")). add(UI.PanelFactory.panel(etfbb). withLabel("&EditorTextField:").withComment("EditorTextField with browse button")). add(UI.PanelFactory.panel(comboBox). withLabel("&ComboBoxEditorTextField:").withComment("EditorComboBox editor")). add(UI.PanelFactory.panel(eComboBox). withLabel("ComboBox &extendable:").withComment("ComboBox with ExtendableTextEditor")). add(UI.PanelFactory.panel(animatedIconComboBox). withLabel("&Animated combobox:").withComment("ComboBox with animated icon")). createPanel(); }