Home
Categories
Dictionary
Download
Project Details
Changes Log
License

Popup menu



The JEditor.setRightClickPopup(JPopupMenu) allows to add a Popup menu which will appear on a right-click in the JEditor area.

Default popup menu

The DefaultEditorPopup class allows to show by default a Cut/ Copy / Paste and Search options.

For example:
      JEditor editor = new JEditor();
      editor.setRightClickPopup(new DefaultEditorPopup());
will show:
defaultPopup

Customizing the popup

The AbstractContextEditorPopup class allows to create a customized popup menu which may change its content depending on the line and column where the popup is called.

The AbstractContextEditorPopup.createPopupItems(int, int) will be called by the JEditor when right clicking on the editor area:
  • The first argument is the line (beginning by 0)
  • The second argument is the column (beginning by 0)
The method return a boolean specifying if a popup menu should appear. For example, the following code will shown a menu presenting the line number and the column:
      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) {
           this.add(new JMenuItem("Line " + (line + 1 ) + " Column " + (column + 1)));
           return true;
         }
      }

contextpopup

Editor defaults

Settings a CodeEditorDefaults.setPopup(JPopupMenu) value for the CodeEditorDefaults class allows to define a Popup which will be shown when right-clicking on the Editor. Any subclass of the AbstractEditorPopup class can be used for the Popup.

Note that setting the value 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);

See also


Categories: component

Copyright 2016-2019 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence