showing popup,
I want to show popup showing all the possible values if a particular token is not correct. This event is triggered when space bar is typed. It works fine. One bug is that, the popup pops up wherever the cursor is in the line, I want to show the popup only where the correct token should have been.
String str = Australia Canberra Dollar
String tokens = str.split("\\s+");
private void editorTextAreaKeyTyped(java.awt.event.KeyEvent evt) {
if ((evt.getKeyChar() == KeyEvent.VK_SPACE)) {
if(!tokens[0].equals("Australia")){
showPopup(editor, menu);
}
}
}
public void showPopUpMenu(JTextArea jTextArea, List menuItems) {
JPopupMenu popup = new JPopupMenu();
Point point = getPoint(jTextArea);
Caret caret = getCaret(jTextArea);
JMenuItem menuItem;
ActionListener al = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jTextArea.insert(e.getActionCommand(), jTextArea.getCaret().getDot());
}
};
for (Object mi : menuItems) {
menuItem = new JMenuItem(mi.toString());
menuItem.addActionListener(al);
popup.add(menuItem);
}
popup.show(jTextArea, point.x, point.y);
}