JComponent (final @NotNull TextFieldWithBrowseButton textAccessor) { final FixedSizeButton button = new FixedSizeButton(textAccessor); button.setIcon(AllIcons.Actions.ListFiles); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final List<String> macros = ContainerUtil.map(myMacrosMap.keySet(), s -> s.startsWith("%") ? s : "$" + s + "$"); JBPopupFactory.getInstance() .createPopupChooserBuilder(macros) .setItemChosenCallback((value) -> textAccessor.setText(value)) .setMovable(false) .setResizable(false) .createPopup() .showUnderneathOf(button); } }); JPanel panel = new JPanel(new BorderLayout()); panel.add(textAccessor, BorderLayout.CENTER); panel.add(button, BorderLayout.EAST); return panel; }