ta.addMouseListener(new MouseAdapter() {
public void mouseReleased(final MouseEvent e) {
if (e.isPopupTrigger()) {
final JPopupMenu menu = new JPopupMenu();
JMenuItem item;
item = new JMenuItem(new DefaultEditorKit.CopyAction());
item.setText("Copy");
item.setEnabled(ta.getSelectionStart() != ta.getSelectionEnd());
menu.add(item);
menu.show(e.getComponent(), e.getX(), e.getY());
}
}
});
Work very well, thanks!
ReplyDeleteIt's wonderful to do a search and find exactly what I was looking for! Thank you!
ReplyDeleteWOW ! Where is the easy button ? Thanks so much for the very elegant code snippet .
ReplyDelete