當前位置: 首頁>>代碼示例>>Java>>正文


Java JPopupMenu.getComponent方法代碼示例

本文整理匯總了Java中javax.swing.JPopupMenu.getComponent方法的典型用法代碼示例。如果您正苦於以下問題:Java JPopupMenu.getComponent方法的具體用法?Java JPopupMenu.getComponent怎麽用?Java JPopupMenu.getComponent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.JPopupMenu的用法示例。


在下文中一共展示了JPopupMenu.getComponent方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getPopupMenuItem

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:22,代碼來源:PolarChartPanel.java

示例2: actionPerformed

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
@Override
public void actionPerformed(ActionEvent evt){
  if(annotationEditor == null) return;
  //this action either creates a new annotation or starts editing an 
  //existing one. In either case we need first to make sure that the current
  //annotation is finished editing.
  if(!annotationEditor.editingFinished()) return;
  if(textLocation == -1) return;
  JPopupMenu popup = new JPopupMenu();

  //check for selection hovering
  if(textPane.getSelectedText() != null
      && textPane.getSelectionStart() <= textLocation
      && textPane.getSelectionEnd() >= textLocation){
    //add 'New annotation' to the popup menu
    popup.add(new NewAnnotationAction(textPane.getSelectedText()));
    popup.addSeparator();
  }

  //check for annotations at location
  for(SetHandler setHandler : setHandlers) {
    for(Annotation ann : setHandler.set.get(
          Math.max(0l, textLocation-1),
          Math.min(document.getContent().size(), textLocation+1))) {
      if(setHandler.getTypeHandler(ann.getType()).isSelected()) {
        AnnotationDataImpl annotAtPoint =
          new AnnotationDataImpl(setHandler.set, ann);
        //add annotations to edit to the popup menu
        popup.add(new HighlightMenuItem(
          new EditAnnotationAction(annotAtPoint),
          annotAtPoint.getAnnotation().getStartNode().getOffset().intValue(),
          annotAtPoint.getAnnotation().getEndNode().getOffset().intValue(),
          popup));
      }
    }
  }

  if (popup.getComponentCount() == 0) {
    // nothing to do
  } else if(popup.getComponentCount() == 1
    || (popup.getComponentCount() == 2
     && popup.getComponent(1) instanceof JSeparator)) {
    //only one annotation, start the editing directly
    //or only one selection, add new annotation
    ((JMenuItem)popup.getComponent(0)).getAction().actionPerformed(evt);
  } else { //mouse hover a selection AND annotation(s)
    try{
      Rectangle rect =  textPane.modelToView(textLocation);
      //display the popup
      popup.show(textPane, rect.x + 10, rect.y);
    }catch(BadLocationException ble){
      throw new GateRuntimeException(ble);
    }
  }
}
 
開發者ID:GateNLP,項目名稱:gate-core,代碼行數:56,代碼來源:AnnotationSetsView.java


注:本文中的javax.swing.JPopupMenu.getComponent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。