There are 21 code examples for javax.swing.JPopupMenu.

The API names are highlighted below. You can use suckoo button to vote the code example(s) you like. The best code example will be ranked first next time. Thanks a lot for your feedback.

Project Name: druid Package: org.dlib.gui.flextable

Source Code: InternalMouseListener.java (Click to view .java file)

Method Code:
vote
like

public void mousePressed(MouseEvent e){
  if (table.getPopupGen() == null)   return;
  if (!e.isMetaDown())   return;
  if (!table.isFocusOwner())   table.requestFocusInWindow();
  int row=table.rowAtPoint(e.getPoint());
  int col=table.columnAtPoint(e.getPoint());
  table.setRowSelectionInterval(row,row);
  Object obj=table.getValueAt(row,col);
  JPopupMenu popup=table.getPopupGen().generate(obj,row,col);
  if (popup == null)   return;
  if (popup.getComponentCount() != 0)   popup.show(table,e.getX(),e.getY());
}
 

Project Name: druid Package: org.dlib.gui.treeview

Source Code: InternalMouseListener.java (Click to view .java file)

Method Code:
vote
like

public void mousePressed(MouseEvent e){
  if (!tree.isFocusOwner())   tree.requestFocusInWindow();
  if (e.isMetaDown()) {
    TreePath path=tree.getPathForLocation(e.getX(),e.getY());
    Object obj=null;
    if (path != null) {
      obj=path.getLastPathComponent();
      tree.setSelectionPath(path);
    }
 else {
      tree.clearSelection();
    }
    if (tree.getPopupGen() == null)     return;
    JPopupMenu popup=tree.getPopupGen().generate(obj);
    if (popup == null)     return;
    if (popup.getComponentCount() != 0)     popup.show(tree,e.getX(),e.getY());
  }
 else {
    tree.setSuperEditable(false);
    Object selObj=tree.getLastSelectedPathComponent();
    if (selObj == null)     return;
    if (e.getClickCount() == 2 && editable) {
      boolean canEdit=true;
      if (tree.getModel() instanceof TreeViewModel) {
        TreeViewModel model=(TreeViewModel)tree.getModel();
        canEdit=model.isEditable(selObj);
      }
      if (canEdit)       tree.startEditingAtSelectedPath();
    }
  }
}
 

Project Name: jFreeChart Package: org.jfree.chart

Source Code: PolarChartPanel.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Returns the index of an item in a popup menu.
 * @param menu  the menu.
 * @param text  the label.
 * @return The item index.
 */
private int getPopupMenuItem(JPopupMenu menu,String text){
  int index=-1;
  for (int i=0; (index == -1) && (i < menu.getComponentCount()); i++) {
    Component comp=menu.getComponent(i);
    if (comp instanceof JMenuItem) {
      JMenuItem item=(JMenuItem)comp;
      if (text.equals(item.getText())) {
        index=i;
      }
    }
  }
  return index;
}
 

Project Name: jFreeChart Package: org.jfree.chart

Source Code: ChartPanel.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Updates the UI for a LookAndFeel change.
 */
public void updateUI(){
  if (this.popup != null) {
    SwingUtilities.updateComponentTreeUI(this.popup);
  }
  super.updateUI();
}
 

Project Name: jbidwatcher Package: com.jbidwatcher.platform

Source Code: Tray.java (Click to view .java file)

Method Code:
vote
like

private boolean tryJava6Tray(final JPopupMenu menu,ImageIcon jbw_icon){
  if (JConfig.queryConfiguration("temp.tray.java6","false").equals("false"))   return false;
  try {
    java6TrayClass=Class.forName("java.awt.SystemTray");
    Method m=java6TrayClass.getMethod("getSystemTray");
    java6tray=m.invoke(null);
    java6TrayIconClass=Class.forName("java.awt.TrayIcon");
    Constructor<?> tiConst=java6TrayIconClass.getConstructor(Image.class,String.class,PopupMenu.class);
    java6icon=tiConst.newInstance(jbw_icon.getImage(),"JBidwatcher",null);
    Method aAML=java6TrayIconClass.getMethod("addMouseListener",MouseListener.class);
    aAML.invoke(java6icon,new MouseAdapter(){
      public void mouseReleased(      MouseEvent e){
        if (e.isPopupTrigger()) {
          menu.setLocation(e.getX(),e.getY());
          menu.setInvoker(menu);
          menu.setVisible(true);
        }
      }
    }
);
    Method sIAS=java6TrayIconClass.getMethod("setImageAutoSize",Boolean.TYPE);
    sIAS.invoke(java6icon,true);
    Method aAL=java6TrayIconClass.getMethod("addActionListener",ActionListener.class);
    aAL.invoke(java6icon,new ActionListener(){
      public void actionPerformed(      ActionEvent e){
        MQFactory.getConcrete("Swing").enqueue("VISIBILITY");
      }
    }
);
    Class[] trayIconClasses=java6TrayIconClass.getClasses();
    for (    Class checkForTypes : trayIconClasses) {
      if (checkForTypes.getName().contains("MessageType")) {
        trayMessageTypeClass=checkForTypes;
      }
    }
    if (trayMessageTypeClass != null) {
      Method valueOf=trayMessageTypeClass.getMethod("valueOf",String.class);
      infoMessageType=valueOf.invoke(null,"INFO");
      return true;
    }
  }
 catch (  Exception e) {
    JConfig.log().handleException("Failed to get system tray!",e);
  }
  return false;
}
 

Project Name: jbidwatcher Package: com.jbidwatcher.platform

Source Code: Tray.java (Click to view .java file)

Method Code:
vote
like

public void mouseReleased(MouseEvent e){
  if (e.isPopupTrigger()) {
    menu.setLocation(e.getX(),e.getY());
    menu.setInvoker(menu);
    menu.setVisible(true);
  }
}
 

Project Name: jbidwatcher Package: com.jbidwatcher.ui

Source Code: JTabPopupMenu.java (Click to view .java file)

Method Code:
vote
like

/** 
 * @brief Use reflection to determine if we have an indexAtLocation
 * function, and always allow them to TRY to delete, if we don't.
 * If we do, figure if it's the bottom three tabs (current,
 * completed, selling) we don't want to allow delete.
 * @param inPopup - The pop-up menu that is going to be displayed.
 * @param e - The event that occurred (a context-operation).
 */
protected void beforePopup(JPopupMenu inPopup,MouseEvent e){
  super.beforePopup(inPopup,e);
  int curIndex=mTabs.indexAtLocation(e.getX(),e.getY());
  if (curIndex == -1) {
    int tabCount=mTabs.getTabCount();
    for (int i=0; i < tabCount; i++) {
      Rectangle tabBounds=mTabs.getBoundsAt(i);
      if (tabBounds != null && tabBounds.contains(e.getPoint()))       curIndex=i;
    }
  }
  preparePopup(curIndex);
}
 

Project Name: jbidwatcher Package: com.jbidwatcher.ui

Source Code: JBidFrameMouse.java (Click to view .java file)

Method Code:
vote
like

public JBidFrameMouse(){
  localPopup=constructFramePopup();
}
 

Project Name: jbidwatcher Package: com.jbidwatcher.ui

Source Code: JBidContext.java (Click to view .java file)

Method Code:
vote
like

protected void beforePopup(JPopupMenu inPopup,MouseEvent e){
  super.beforePopup(inPopup,e);
  if (!(e.getComponent() instanceof JComponent))   return;
  JComponent inComponent=(JComponent)e.getComponent();
  if (inComponent instanceof JTable) {
    _inTable=(JTable)inComponent;
    int row=_inTable.rowAtPoint(e.getPoint());
    if (!_inTable.isRowSelected(row))     _inTable.setRowSelectionInterval(row,row);
  }
}
 

Project Name: jbidwatcher Package: com.jbidwatcher.ui

Source Code: JSearchContext.java (Click to view .java file)

Method Code:
vote
like

public JSearchContext(){
  localPopup=constructTablePopup();
}
 

Project Name: jbidwatcher Package: com.jbidwatcher.ui.util

Source Code: JMouseAdapter.java (Click to view .java file)

Method Code:
vote
like

private void internalPopupMenu(MouseEvent e){
  Component activeComp=(Component)e.getSource();
  localPopup.show(activeComp,x,y);
  Point point=localPopup.getLocationOnScreen();
  Dimension size=localPopup.getSize();
  Rectangle oldRect=new Rectangle(point.x,point.y,size.width,size.height);
  Rectangle newRect=ensureRectIsVisible(oldRect);
  if (!oldRect.equals(newRect)) {
    localPopup.setLocation(newRect.x,newRect.y);
  }
}
 

Project Name: jbidwatcher Package: com.jbidwatcher.ui.util

Source Code: JPasteListener.java (Click to view .java file)

Method Code:
vote
like

public void mouseClicked(MouseEvent me){
  int modifiers=me.getModifiers();
  if (isHit(modifiers,MouseEvent.BUTTON2_MASK) && !Platform.isLinux()) {
    JTextField jtfEvent=(JTextField)me.getComponent();
    jtfEvent.paste();
  }
 else   if (me.isPopupTrigger()) {
    _me=me;
    _jpm.show(me.getComponent(),me.getX(),me.getY());
  }
}
 

Project Name: jbidwatcher Package: com.jbidwatcher.ui.util

Source Code: JContext.java (Click to view .java file)

Method Code:
vote
like

protected void beforePopup(JPopupMenu inPopup,MouseEvent e){
  super.beforePopup(inPopup,e);
  enableAll();
}
 

Project Name: vfsjfilechooser Package: net.sf.vfsjfilechooser.filechooser

Source Code: PopupHandler.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Returns the popup menu associated to this listener
 * @return The popup menu associated to this listener
 */
public JPopupMenu getPopup(){
  return popup;
}
 

Project Name: vfsjfilechooser Package: net.sf.vfsjfilechooser.filepane

Source Code: VFSFilePane.java (Click to view .java file)

Method Code:
vote
like

@Override public JPopupMenu getComponentPopupMenu(){
  JPopupMenu popupMenu=getFileChooser().getComponentPopupMenu();
  if (popupMenu != null) {
    return popupMenu;
  }
  JMenu aViewMenu=getViewMenu();
  if (contextMenu == null) {
    contextMenu=new JPopupMenu();
    if (aViewMenu != null) {
      contextMenu.add(aViewMenu);
      if (listViewWindowsStyle) {
        contextMenu.addSeparator();
      }
    }
    ActionMap actionMap=getActionMap();
    Action refreshAction=actionMap.get(ACTION_REFRESH);
    Action aNewFolderAction=actionMap.get(ACTION_NEW_FOLDER);
    if (refreshAction != null) {
      contextMenu.add(refreshAction);
      if (listViewWindowsStyle && (aNewFolderAction != null)) {
        contextMenu.addSeparator();
      }
    }
    if (aNewFolderAction != null) {
      contextMenu.add(aNewFolderAction);
    }
  }
  if (aViewMenu != null) {
    aViewMenu.getPopupMenu().setInvoker(aViewMenu);
  }
  return contextMenu;
}
 

Project Name: weka Package: weka.gui

Source Code: GenericObjectEditorHistory.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Adds a menu item with the history to the popup menu.
 * @param menu	the menu to add the history to
 * @param current	the current object
 * @param listener	the listener to attach to the menu items' ActionListener
 */
public void customizePopupMenu(JPopupMenu menu,Object current,HistorySelectionListener listener){
  JMenu submenu;
  JMenuItem item;
  int i;
  if (m_History.size() == 0)   return;
  submenu=new JMenu("History");
  menu.addSeparator();
  menu.add(submenu);
  item=new JMenuItem("Clear history");
  item.addActionListener(new ActionListener(){
    public void actionPerformed(    ActionEvent e){
      m_History.clear();
    }
  }
);
  submenu.add(item);
  final HistorySelectionListener fListener=listener;
  for (i=0; i < m_History.size(); i++) {
    if (i == 0)     submenu.addSeparator();
    final Object history=m_History.get(i);
    item=new JMenuItem(generateMenuItemCaption(history));
    item.addActionListener(new ActionListener(){
      public void actionPerformed(      ActionEvent e){
        fListener.historySelected(new HistorySelectionEvent(fListener,history));
      }
    }
);
    submenu.add(item);
  }
}
 

Project Name: weka Package: weka.gui

Source Code: GenericObjectEditor.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Returns a popup menu that allows the user to change
 * the class of object.
 * @return a JPopupMenu that when shown will let the user choose the class
 */
public JPopupMenu getChooseClassPopupMenu(){
  updateObjectNames();
  m_treeNodeOfCurrentObject=null;
  final JTree tree=createTree(m_ObjectNames);
  if (m_treeNodeOfCurrentObject != null) {
    tree.setSelectionPath(new TreePath(m_treeNodeOfCurrentObject.getPath()));
  }
  tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  final JPopupMenu popup=new JTreePopupMenu(tree);
  tree.addTreeSelectionListener(new TreeSelectionListener(){
    public void valueChanged(    TreeSelectionEvent e){
      GOETreeNode node=(GOETreeNode)tree.getLastSelectedPathComponent();
      if (node == null)       return;
      if (node.isLeaf()) {
        classSelected(getClassnameFromPath(tree.getSelectionPath()));
        popup.setVisible(false);
      }
    }
  }
);
  return popup;
}
 

Project Name: weka Package: weka.gui

Source Code: LogPanel.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Add a popup menu for displaying the amount of free memory
 * and running the garbage collector
 */
private void addPopup(){
  addMouseListener(new MouseAdapter(){
    public void mouseClicked(    MouseEvent e){
      if (((e.getModifiers() & InputEvent.BUTTON1_MASK) != InputEvent.BUTTON1_MASK) || e.isAltDown()) {
        JPopupMenu gcMenu=new JPopupMenu();
        JMenuItem availMem=new JMenuItem("Memory information");
        availMem.addActionListener(new ActionListener(){
          public void actionPerformed(          ActionEvent ee){
            System.gc();
            Runtime currR=Runtime.getRuntime();
            long freeM=currR.freeMemory();
            long totalM=currR.totalMemory();
            long maxM=currR.maxMemory();
            logMessage("Memory (free/total/max.) in bytes: " + printLong(freeM) + " / "+ printLong(totalM)+ " / "+ printLong(maxM));
            statusMessage("Memory (free/total/max.) in bytes: " + printLong(freeM) + " / "+ printLong(totalM)+ " / "+ printLong(maxM));
          }
        }
);
        gcMenu.add(availMem);
        JMenuItem runGC=new JMenuItem("Run garbage collector");
        runGC.addActionListener(new ActionListener(){
          public void actionPerformed(          ActionEvent ee){
            statusMessage("Running garbage collector");
            System.gc();
            statusMessage("OK");
          }
        }
);
        gcMenu.add(runGC);
        gcMenu.show(LogPanel.this,e.getX(),e.getY());
      }
    }
  }
);
}
 

Project Name: weka Package: weka.gui

Source Code: LogPanel.java (Click to view .java file)

Method Code:
vote
like

public void mouseClicked(MouseEvent e){
  if (((e.getModifiers() & InputEvent.BUTTON1_MASK) != InputEvent.BUTTON1_MASK) || e.isAltDown()) {
    JPopupMenu gcMenu=new JPopupMenu();
    JMenuItem availMem=new JMenuItem("Memory information");
    availMem.addActionListener(new ActionListener(){
      public void actionPerformed(      ActionEvent ee){
        System.gc();
        Runtime currR=Runtime.getRuntime();
        long freeM=currR.freeMemory();
        long totalM=currR.totalMemory();
        long maxM=currR.maxMemory();
        logMessage("Memory (free/total/max.) in bytes: " + printLong(freeM) + " / "+ printLong(totalM)+ " / "+ printLong(maxM));
        statusMessage("Memory (free/total/max.) in bytes: " + printLong(freeM) + " / "+ printLong(totalM)+ " / "+ printLong(maxM));
      }
    }
);
    gcMenu.add(availMem);
    JMenuItem runGC=new JMenuItem("Run garbage collector");
    runGC.addActionListener(new ActionListener(){
      public void actionPerformed(      ActionEvent ee){
        statusMessage("Running garbage collector");
        System.gc();
        statusMessage("OK");
      }
    }
);
    gcMenu.add(runGC);
    gcMenu.show(LogPanel.this,e.getX(),e.getY());
  }
}
 

Project Name: weka Package: weka.gui.arffviewer

Source Code: ArffPanel.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Invoked when a mouse button has been pressed and released on a component
 * @param e		the mouse event
 */
public void mouseClicked(MouseEvent e){
  int col;
  boolean popup;
  col=m_TableArff.columnAtPoint(e.getPoint());
  popup=((e.getButton() == MouseEvent.BUTTON3) && (e.getClickCount() == 1)) || ((e.getButton() == MouseEvent.BUTTON1) && (e.getClickCount() == 1) && e.isAltDown()&& !e.isControlDown()&& !e.isShiftDown());
  popup=popup && (getInstances() != null);
  if (e.getSource() == m_TableArff.getTableHeader()) {
    m_CurrentCol=col;
    if (popup) {
      e.consume();
      setMenu();
      initPopupMenus();
      m_PopupHeader.show(e.getComponent(),e.getX(),e.getY());
    }
  }
 else   if (e.getSource() == m_TableArff) {
    if (popup) {
      e.consume();
      setMenu();
      initPopupMenus();
      m_PopupRows.show(e.getComponent(),e.getX(),e.getY());
    }
  }
  if ((e.getButton() == MouseEvent.BUTTON1) && (e.getClickCount() == 1) && (!e.isAltDown())&& (col > -1)) {
    m_TableArff.setSelectedColumn(col);
  }
}
 

Project Name: weka Package: weka.gui.beans

Source Code: BeanConnection.java (Click to view .java file)

Method Code:
vote
like

public static void doMetaConnection(BeanInstance source,BeanInstance target,final EventSetDescriptor esd,final JComponent displayComponent,final int tab){
  Object targetBean=target.getBean();
  BeanInstance realTarget=null;
  final BeanInstance realSource=source;
  if (targetBean instanceof MetaBean) {
    Vector receivers=((MetaBean)targetBean).getSuitableTargets(esd);
    if (receivers.size() == 1) {
      realTarget=(BeanInstance)receivers.elementAt(0);
      BeanConnection bc=new BeanConnection(realSource,realTarget,esd,tab);
    }
 else {
      int menuItemCount=0;
      JPopupMenu targetConnectionMenu=new JPopupMenu();
      targetConnectionMenu.insert(new JLabel("Select target",SwingConstants.CENTER),menuItemCount++);
      for (int i=0; i < receivers.size(); i++) {
        final BeanInstance tempTarget=(BeanInstance)receivers.elementAt(i);
        String tName="" + (i + 1) + ": "+ ((tempTarget.getBean() instanceof BeanCommon) ? ((BeanCommon)tempTarget.getBean()).getCustomName() : tempTarget.getBean().getClass().getName());
        JMenuItem targetItem=new JMenuItem(tName);
        targetItem.addActionListener(new ActionListener(){
          public void actionPerformed(          ActionEvent e){
            BeanConnection bc=new BeanConnection(realSource,tempTarget,esd,tab);
            displayComponent.repaint();
          }
        }
);
        targetConnectionMenu.add(targetItem);
        menuItemCount++;
      }
      targetConnectionMenu.show(displayComponent,target.getX(),target.getY());
    }
  }
}