Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

34
LINES

< > BotCompany Repo | #1000839 - PopupMenuHelper

JavaX fragment (include)

static class PopupMenuHelper extends MouseAdapter {
  JPopupMenu menu;
  Point point;
  
  /** override me  */
  void fillMenu() {
  }

  public void mousePressed(MouseEvent e) {
    displayMenu(e);
  }

  public void mouseReleased(MouseEvent e) {
    displayMenu(e);
  }

  private void displayMenu(MouseEvent e) {
    boolean popupTrigger = e.isPopupTrigger();
    if (popupTrigger) {
      JPopupMenu menu = new JPopupMenu();
      int count = menu.getComponentCount();
      this.menu = menu;
      this.point = e.getPoint();
      fillMenu();
      this.menu = null;
      if (menu.getComponentCount() != count)
        menu.show(e.getComponent(), e.getX(), e.getY());
    }
  }

  public void install(JComponent component) {
    component.addMouseListener(this);
  }
}

download  show line numbers  debug dex   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1000839
Snippet name: PopupMenuHelper
Eternal ID of this version: #1000839/1
Text MD5: 1187cb3d07808feb5a5450f117e2072d
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-23 22:00:09
Source code size: 807 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 461 / 2281
Referenced in: [show references]

Formerly at http://tinybrain.de/1000839 & http://1000839.tinybrain.de