当前位置: 首页>>代码示例>>Java>>正文


Java JPopupMenu.getComponentCount方法代码示例

本文整理汇总了Java中javax.swing.JPopupMenu.getComponentCount方法的典型用法代码示例。如果您正苦于以下问题:Java JPopupMenu.getComponentCount方法的具体用法?Java JPopupMenu.getComponentCount怎么用?Java JPopupMenu.getComponentCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JPopupMenu的用法示例。


在下文中一共展示了JPopupMenu.getComponentCount方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: displayPopup

import javax.swing.JPopupMenu; //导入方法依赖的package包/类
public void displayPopup() {
    JPopupMenu menu = new JPopupMenu();
    populatePopup(menu);
    if (menu.getComponentCount() > 0) {
        Dimension size = menu.getPreferredSize();
        size.width = Math.max(size.width, getWidth());
        menu.setPreferredSize(size);
        menu.show(this, 0, getHeight());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:DropdownButton.java

示例2: showPopupMenu

import javax.swing.JPopupMenu; //导入方法依赖的package包/类
private void showPopupMenu(MouseEvent e) {
    JPopupMenu popup = new JPopupMenu() {
        public void setVisible(boolean visible) {
            if (visible) popupShowing();
            super.setVisible(visible);
            if (!visible) popupHidden();
        }
    };
    
    int row = getSelectedRow();
    Object value = getValueForRow(row);
    Object userValue = getUserValueForRow(row);
    populatePopup(popup, value, userValue);
    
    if (popup.getComponentCount() > 0) {
        if (e == null) {
            boolean b = row == -1;
            int c = b ? -1 : convertColumnIndexToView(mainColumn);
            Rectangle t = b ? getVisibleRect() : getCellRect(row, c, false);
            Dimension s = popup.getPreferredSize();
            int x = t.x + (t.width - s.width) / 2;
            int y = t.y + (b ? (t.height - s.height) / 2 : getRowHeight() - 4);
            popup.show(this, Math.max(x, 0), Math.max(y, 0));
        } else {
            popup.show(this, e.getX(), e.getY());
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:ProfilerTable.java

示例3: displayPopup

import javax.swing.JPopupMenu; //导入方法依赖的package包/类
protected void displayPopup() {
    JPopupMenu menu = new JPopupMenu();
    populatePopup(menu);
    if (menu.getComponentCount() > 0) {
        Dimension size = menu.getPreferredSize();
        size.width = Math.max(size.width, getWidth());
        menu.setPreferredSize(size);
        
        int align = getPopupAlign();
        
        int x;
        switch (align) {
            case SwingConstants.EAST:
            case SwingConstants.NORTH_EAST:
            case SwingConstants.SOUTH_EAST:
                x = getWidth() - size.width;
                break;
            default:
                x = 0;
                break;
        }
        
        int y;
        switch (align) {
            case SwingConstants.NORTH:
            case SwingConstants.NORTH_EAST:
            case SwingConstants.NORTH_WEST:
                y = -size.height;
                break;
            default:
                y = getHeight();
                break;
        }
        
        menu.show(this, x, y);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:PopupButton.java

示例4: showPopup

import javax.swing.JPopupMenu; //导入方法依赖的package包/类
private void showPopup (Point e, Component invoker) {
    int row = UnitTab.this.table.rowAtPoint (e);
    if (row >= 0) {
        table.getSelectionModel ().setSelectionInterval (row, row);
        final JPopupMenu finalPopup = popupActionsSupport.createPopup ();
        if (finalPopup != null && finalPopup.getComponentCount () > 0) {
            finalPopup.show (invoker,e.x, e.y);
            
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:UnitTab.java

示例5: buildPopupForRoom

import javax.swing.JPopupMenu; //导入方法依赖的package包/类
public JPopupMenu buildPopupForRoom(Room room, JTree tree) {
  JPopupMenu popup = new JPopupMenu();
  for (RoomActionFactory f : roomActionFactories) {
    popup.add(f.getAction(room, tree));
  }
  return popup.getComponentCount() == 0 ? null : popup;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:8,代码来源:RoomInteractionControlsInitializer.java

示例6: buildPopupForPlayer

import javax.swing.JPopupMenu; //导入方法依赖的package包/类
public JPopupMenu buildPopupForPlayer(SimplePlayer target, JTree tree) {
  JPopupMenu popup = new JPopupMenu();
  for (PlayerActionFactory f : playerActionFactories) {
    final Action a = f.getAction(target, tree);
    if (a != null) {
      popup.add(a);
    }
  }
  return popup.getComponentCount() == 0 ? null : popup;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:11,代码来源:RoomInteractionControlsInitializer.java

示例7: addShowHideItems

import javax.swing.JPopupMenu; //导入方法依赖的package包/类
/** Adds menu items for graying out. */
private void addShowHideItems(JPopupMenu result) {
    // add the show/hide menu
    @SuppressWarnings({"unchecked", "rawtypes"})
    JPopupMenu restMenu = new ShowHideMenu(this.jGraph).getPopupMenu();
    while (restMenu.getComponentCount() > 0) {
        result.add(restMenu.getComponent(0));
    }
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:10,代码来源:LabelTree.java

示例8: setMenuText

import javax.swing.JPopupMenu; //导入方法依赖的package包/类
public static void setMenuText(final JPopupMenu menu) {
    for (int i = 0; i < menu.getComponentCount(); i++) {
        if (isParent(JMenuItem.class, menu.getComponent(i).getClass()))
            setMenuItemText((JMenuItem) menu.getComponent(i));
        else if (menu.getComponent(i).getClass() == JMenu.class)
            setMenuText((JMenu) menu.getComponent(i));
        else if (isParent(JRadioButtonMenuItem.class, menu.getComponent(i)
                .getClass()))
            setMenuItemText((JRadioButtonMenuItem) menu.getComponent(i));

    }
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:13,代码来源:ResourceLoader.java

示例9: configurePopupMenu

import javax.swing.JPopupMenu; //导入方法依赖的package包/类
/**
 * Overridden to toggle the enabled state of various
 * RSyntaxTextArea-specific menu items.
 *
 * If you set the popup menu via {@link #setPopupMenu(JPopupMenu)}, you
 * will want to override this method, especially if you removed any of the
 * menu items in the default popup menu.
 *
 * @param popupMenu The popup menu.  This will never be <code>null</code>.
 * @see #createPopupMenu()
 * @see #setPopupMenu(JPopupMenu)
 */
@Override
protected void configurePopupMenu(JPopupMenu popupMenu) {

	super.configurePopupMenu(popupMenu);

	// They may have overridden createPopupMenu()...
	if (popupMenu!=null && popupMenu.getComponentCount()>0 &&
			foldingMenu!=null) {
		foldingMenu.setEnabled(foldManager.
					isCodeFoldingSupportedAndEnabled());
	}
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:25,代码来源:RSyntaxTextArea.java

示例10: 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

示例11: buildPopup

import javax.swing.JPopupMenu; //导入方法依赖的package包/类
protected JPopupMenu buildPopup() {
  JPopupMenu popup = new JPopupMenu();
  return popup.getComponentCount() > 0 ? popup : null;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:5,代码来源:DrawPile.java

示例12: 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

示例13: createPopupMenu

import javax.swing.JPopupMenu; //导入方法依赖的package包/类
/**
 * Creates a popup menu for the panel.
 *
 * @param properties  include a menu item for the chart property editor.
 * @param save  include a menu item for saving the chart.
 * @param print  include a menu item for printing the chart.
 * @param zoom  include menu items for zooming.
 *
 * @return The popup menu.
 */
protected JPopupMenu createPopupMenu(boolean properties,
                                     boolean save, 
                                     boolean print, 
                                     boolean zoom) {
    
   JPopupMenu result = super.createPopupMenu(properties, save, print, zoom);
   int zoomInIndex  = getPopupMenuItem(result, "Zoom In");
   int zoomOutIndex = getPopupMenuItem(result, "Zoom Out");
   int autoIndex     = getPopupMenuItem(result, "Auto Range");
   if (zoom) {
       JMenuItem zoomIn = new JMenuItem("Zoom In");
       zoomIn.setActionCommand(POLAR_ZOOM_IN_ACTION_COMMAND);
       zoomIn.addActionListener(this);
      
       JMenuItem zoomOut = new JMenuItem("Zoom Out");
       zoomOut.setActionCommand(POLAR_ZOOM_OUT_ACTION_COMMAND);
       zoomOut.addActionListener(this);
      
       JMenuItem auto = new JMenuItem("Auto Range");
       auto.setActionCommand(POLAR_AUTO_RANGE_ACTION_COMMAND);
       auto.addActionListener(this);
      
       if (zoomInIndex != -1) {
           result.remove(zoomInIndex);
       }
       else {
           zoomInIndex = result.getComponentCount() - 1;
       }
       result.add(zoomIn, zoomInIndex);
       if (zoomOutIndex != -1) {
           result.remove(zoomOutIndex);
       }
       else {
           zoomOutIndex = zoomInIndex + 1;
       }
       result.add(zoomOut, zoomOutIndex);
       if (autoIndex != -1) {
           result.remove(autoIndex);
       }
       else {
           autoIndex = zoomOutIndex + 1;
       }
       result.add(auto, autoIndex);
   }
   return result;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:57,代码来源:PolarChartPanel.java


注:本文中的javax.swing.JPopupMenu.getComponentCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。