JEditor editor = new JEditor(); editor.setRightClickPopup(new DefaultEditorPopup());will show:
JEditor() editor = new JEditor(); editor.setRightClickPopup(new ContextPopup()); public class ContextPopup extends AbstractContextEditorPopup { public ContextPopup() { super("Popup"); } @Override protected boolean createPopupItems(int line, int column, int startSelection, int endSelection) { this.add(new JMenuItem("Line " + (line + 1 ) + " Column " + (column + 1))); return true; } }
JEditor() editor = new JEditor(); editor.setRightClickPopup(new ContextPopup()); public class ContextPopup extends AbstractContextEditorPopup { public ContextPopup() { super("Popup"); } @Override protected boolean createPopupItems(int line, int column, int startSelection, int endSelection) { if (startSelection == endSelection) { JMenuItem insertItem = new JMenuItem(new AbstractAction("Insert Text") { @Override public void actionPerformed(ActionEvent e) { editor.insertText(startSelection, "The Inserted Text"); } }); this.add(insertItem); return true; } else { return false; } } }
true
for the CodeEditorDefaults.hasPopup value will also show the DefaultEditorPopup
. For example, the following code will also allow to show the same Popup:defaults.hasPopup = true; JEditor ta = new JEditor(defaults);
Copyright 2016-2019 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence