package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import java.util.Objects;
import javax.swing.*;
import javax.swing.plaf.basic.*;
import javax.swing.text.*;

public final class MainPanel extends JPanel {
    private final JTextPane jtp = new JTextPane();
    private final JComboBox<String> combo = new JComboBox<>(new String[] {
        "public", "protected", "private",
        "final", "transient", "super", "this", "return", "class"
    });
    private final BasicComboPopup popup = new EditorComboPopup(jtp, combo);
    public MainPanel() {
        super(new BorderLayout());

        ActionMap amc = popup.getActionMap();
        amc.put("myUp", new AbstractAction() {
            @Override public void actionPerformed(ActionEvent e) {
                int index = combo.getSelectedIndex();
                combo.setSelectedIndex(index == 0 ? combo.getItemCount() - 1 : index - 1);
            }
        });
        amc.put("myDown", new AbstractAction() {
            @Override public void actionPerformed(ActionEvent e) {
                int index = combo.getSelectedIndex();
                combo.setSelectedIndex(index == combo.getItemCount() - 1 ? 0 : index + 1);
            }
        });
        amc.put("myEnt", new AbstractAction() {
            @Override public void actionPerformed(ActionEvent e) {
                append((String) combo.getSelectedItem());
            }
        });

        InputMap imc = popup.getInputMap();
        imc.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0),    "myUp");
        imc.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0),  "myDown");
        imc.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "myEnt");

        jtp.getActionMap().put("myPop", new AbstractAction() {
            @Override public void actionPerformed(ActionEvent e) {
                try {
                    Rectangle rect = jtp.modelToView(jtp.getCaretPosition());
                    popup.show(jtp, rect.x, rect.y + rect.height);
//                     Container c = popup.getTopLevelAncestor();
//                     if (c instanceof Window) {
//                         ((Window) c).toFront();
//                     }
                    popup.requestFocusInWindow();
                } catch (BadLocationException ble) {
                    ble.printStackTrace();
                }
            }
        });
        jtp.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_DOWN_MASK), "myPop");

        add(new JScrollPane(jtp));
        setPreferredSize(new Dimension(320, 240));
    }
    private void append(String str) {
        popup.hide();
        try {
            Document doc = jtp.getDocument();
            doc.insertString(jtp.getCaretPosition(), str, null);
        } catch (BadLocationException ex) {
            ex.printStackTrace();
        }
    }

    public static void main(String... args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGUI();
            }
        });
    }
    public static void createAndShowGUI() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException
               | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        }
        JFrame frame = new JFrame("@title@");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

class EditorComboPopup extends BasicComboPopup {
    private final JTextComponent textArea;
    private transient MouseAdapter listener;
    protected EditorComboPopup(JTextComponent textArea, JComboBox cb) {
        super(cb);
        this.textArea = textArea;
    }
    @Override protected void installListListeners() {
        super.installListListeners();
        listener = new MouseAdapter() {
            @Override public void mouseClicked(MouseEvent e) {
                hide();
                String str = (String) comboBox.getSelectedItem();
                try {
                    Document doc = textArea.getDocument();
                    doc.insertString(textArea.getCaretPosition(), str, null);
                } catch (BadLocationException ex) {
                    ex.printStackTrace();
                }
            }
        };
        if (Objects.nonNull(list)) {
            list.addMouseListener(listener);
        }
    }
    @Override public void uninstallingUI() {
        if (Objects.nonNull(listener)) {
            list.removeMouseListener(listener);
            listener = null;
        }
        super.uninstallingUI();
    }
    @Override public boolean isFocusable() {
        return true;
    }
}

@@ -2043,18 +2043,70 @@
 eight);%0A
-//
+                    EventQueue.invokeLater(() -%3E %7B%0A   
         
@@ -2157,26 +2157,27 @@
 Ancestor();%0A
-//
+   
             
@@ -2212,18 +2212,19 @@
 ndow) %7B%0A
-//
+   
         
@@ -2264,18 +2264,19 @@
 ront();%0A
-//
+   
         
@@ -2282,32 +2282,36 @@
               %7D%0A
+    
                 
@@ -2340,24 +2340,48 @@
 InWindow();%0A
+                    %7D);%0A
             

bring a BasicComboPopup to the front on linux