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


Java JPopupMenu.addPopupMenuListener方法代碼示例

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


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

示例1: doSelect

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
private void doSelect(JComponent owner) {
    invokingComponent = owner;
    invokingComponent.addMouseListener(this);
    invokingComponent.addMouseMotionListener(this);
    pTable.addMouseListener(this);
    pTable.addMouseMotionListener(this);
    pTable.getSelectionModel().addListSelectionListener( this );

    displayer.getModel().addComplexListDataListener( this );

    Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);

    popup = new JPopupMenu();
    popup.setBorderPainted( false );
    popup.setBorder( BorderFactory.createEmptyBorder() );
    popup.add( pTable );
    popup.pack();
    int locationX = x - (int) pTable.getPreferredSize().getWidth();
    int locationY = y + 1;
    popup.setLocation( locationX, locationY );
    popup.setInvoker( invokingComponent );
    popup.addPopupMenuListener( this );
    popup.setVisible( true );
    shown = true;
    invocationTime = System.currentTimeMillis();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:ButtonPopupSwitcher.java

示例2: doSelect

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
private void doSelect(JComponent owner) {
    invokingComponent = owner;
    invokingComponent.addMouseListener(this);
    invokingComponent.addMouseMotionListener(this);
    pTable.addMouseListener(this);
    pTable.addMouseMotionListener(this);
    pTable.getSelectionModel().addListSelectionListener( this );

    controller.getTabModel().addComplexListDataListener( this );

    Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);

    popup = new JPopupMenu();
    popup.setBorderPainted( false );
    popup.setBorder( BorderFactory.createEmptyBorder() );
    popup.add( pTable );
    popup.pack();
    int locationX = x - (int) pTable.getPreferredSize().getWidth();
    int locationY = y + 1;
    popup.setLocation( locationX, locationY );
    popup.setInvoker( invokingComponent );
    popup.addPopupMenuListener( this );
    popup.setVisible( true );
    shown = true;
    invocationTime = System.currentTimeMillis();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:ButtonPopupSwitcher.java

示例3: actionPerformed

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
@Override
public void actionPerformed(ActionEvent ae) {
	JPopupMenu popup = getPopupMenu();
	popup.addPopupMenuListener(popupMenuListener);

	int popupPrefHeight = (int) popup.getPreferredSize().getHeight();
	int buttonY = mainButton.getLocationOnScreen().y;

	boolean showOnTop = false;

	GraphicsConfiguration graphicsConf = ApplicationFrame.getApplicationFrame().getGraphicsConfiguration();
	if (graphicsConf != null) {
		int windowHeight = (int) graphicsConf.getBounds().getHeight();
		showOnTop = buttonY + mainButton.getHeight() + popupPrefHeight > windowHeight;
	}

	if (showOnTop) {
		popup.show(mainButton, 0, -popupPrefHeight);
	} else {
		popup.show(mainButton, 0, mainButton.getHeight());
	}
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:23,代碼來源:FancyDropDownButton.java

示例4: MenuScroller

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
/**
 * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
 * specified number of items to display in the scrolling region, the
 * specified scrolling interval, and the specified numbers of items fixed at
 * the top and bottom of the popup menu.
 *
 * @param menu the popup menu
 * @param scrollCount the number of items to display in the scrolling portion
 * @param interval the scroll interval, in milliseconds
 * @param topFixedCount the number of items to fix at the top.  May be 0
 * @param bottomFixedCount the number of items to fix at the bottom.  May be 0
 * @throws IllegalArgumentException if scrollCount or interval is 0 or
 * negative or if topFixedCount or bottomFixedCount is negative
 */
public MenuScroller(JPopupMenu menu, int scrollCount, int interval,
        int topFixedCount, int bottomFixedCount) {
  if (scrollCount <= 0 || interval <= 0) {
    throw new IllegalArgumentException("scrollCount and interval must be greater than 0");
  }
  if (topFixedCount < 0 || bottomFixedCount < 0) {
    throw new IllegalArgumentException("topFixedCount and bottomFixedCount cannot be negative");
  }

  upItem = new MenuScrollItem(MenuIcon.UP, -1);
  downItem = new MenuScrollItem(MenuIcon.DOWN, +1);
  setScrollCount(scrollCount);
  setInterval(interval);
  setTopFixedCount(topFixedCount);
  setBottomFixedCount(bottomFixedCount);

  this.menu = menu;
  menu.addPopupMenuListener(menuListener);
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:34,代碼來源:MenuScroller.java

示例5: MenuScroller

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
/**
 * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
 * specified number of items to display in the scrolling region, the
 * specified scrolling interval, and the specified numbers of items fixed at
 * the top and bottom of the popup menu.
 * 
 * @param menu the popup menu
 * @param scrollCount the number of items to display in the scrolling portion
 * @param interval the scroll interval, in milliseconds
 * @param topFixedCount the number of items to fix at the top.  May be 0
 * @param bottomFixedCount the number of items to fix at the bottom.  May be 0
 * @throws IllegalArgumentException if scrollCount or interval is 0 or
 * negative or if topFixedCount or bottomFixedCount is negative
 */
public MenuScroller(JPopupMenu menu, int scrollCount, int interval,
        int topFixedCount, int bottomFixedCount) {
  if (scrollCount <= 0 || interval <= 0) {
    throw new IllegalArgumentException("scrollCount and interval must be greater than 0");
  }
  if (topFixedCount < 0 || bottomFixedCount < 0) {
    throw new IllegalArgumentException("topFixedCount and bottomFixedCount cannot be negative");
  }

  upItem = new MenuScrollItem(MenuIcon.UP, -1);
  downItem = new MenuScrollItem(MenuIcon.DOWN, +1);
  setScrollCount(scrollCount);
  setInterval(interval);
  setTopFixedCount(topFixedCount);
  setBottomFixedCount(bottomFixedCount);

  this.menu = menu;
  menu.addPopupMenuListener(menuListener);
}
 
開發者ID:SensorsINI,項目名稱:jaer,代碼行數:34,代碼來源:MenuScroller.java

示例6: MenuScroller

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
/**
 * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
 * specified number of items to display in the scrolling region, the
 * specified scrolling interval, and the specified numbers of items fixed at
 * the top and bottom of the popup menu.
 *
 * @param menu the popup menu
 * @param scrollCount the number of items to display in the scrolling
 * portion
 * @param interval the scroll interval, in milliseconds
 * @param topFixedCount the number of items to fix at the top. May be 0
 * @param bottomFixedCount the number of items to fix at the bottom. May be
 * 0
 * @throws IllegalArgumentException if scrollCount or interval is 0 or
 * negative or if topFixedCount or bottomFixedCount is negative
 */
public MenuScroller(JPopupMenu menu, int scrollCount, int interval,
        int topFixedCount, int bottomFixedCount) {
    if (scrollCount <= 0 || interval <= 0) {
        throw new IllegalArgumentException("scrollCount and interval must be greater than 0");
    }
    if (topFixedCount < 0 || bottomFixedCount < 0) {
        throw new IllegalArgumentException("topFixedCount and bottomFixedCount cannot be negative");
    }

    upItem = new MenuScrollItem(MenuIcon.UP, -1);
    downItem = new MenuScrollItem(MenuIcon.DOWN, +1);
    setScrollCount(scrollCount);
    setInterval(interval);
    setTopFixedCount(topFixedCount);
    setBottomFixedCount(bottomFixedCount);

    this.menu = menu;
    menu.addPopupMenuListener(menuListener);
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:36,代碼來源:MenuScroller.java

示例7: getToolbarPresenter

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
@Override
public Component getToolbarPresenter() {
   
        JPopupMenu menu = new JPopupMenu();
        JButton button = DropDownButtonFactory.createDropDownButton(
                new ImageIcon(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)), menu);
        final JMenuItem item = new JMenuItem(org.openide.awt.Actions.cutAmpersand((String) getValue("menuText")));
        item.setEnabled(isEnabled());

        addPropertyChangeListener(new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                String propName = evt.getPropertyName();
                if ("enabled".equals(propName)) {
                    item.setEnabled((Boolean) evt.getNewValue());
                } else if ("menuText".equals(propName)) {
                    item.setText(org.openide.awt.Actions.cutAmpersand((String) evt.getNewValue()));
                }
            }
        });

        menu.add(item);
        item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                MainProjectActionWithHistory.this.actionPerformed(e);
            }
        });
       
        org.openide.awt.Actions.connect(button, this);
        menu.addPopupMenuListener(this);
        return button;
    
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:35,代碼來源:MainProjectActionWithHistory.java

示例8: fillSubmenu

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
private void fillSubmenu(JPopupMenu pop) {
    if (lastPopup == null) {
        pop.addPopupMenuListener(this);
        lastPopup = pop;

        removeAll();

        Iterator it = generate(toolsAction, false).iterator();

        while (it.hasNext()) {
            java.awt.Component item = (java.awt.Component) it.next();

            if (item == null) {
                addSeparator();
            } else {
                add(item);
            }
        }

        // also work with empty element
        if (getMenuComponentCount() == 0) {
            JMenuItem empty = new JMenuItem(NbBundle.getMessage(ToolsAction.class, "CTL_EmptySubMenu"));
            empty.setEnabled(false);
            add(empty);
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:28,代碼來源:ToolsAction.java

示例9: actionPerformed

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
@Override
public void actionPerformed(ActionEvent ae) {
	JPopupMenu popup = getPopupMenu();
	popup.addPopupMenuListener(popupMenuListener);
	popup.show(mainButton,
			isRightAlign() ? -popup.getPreferredSize().width + mainButton.getWidth() + arrowButton.getWidth() : 0,
			mainButton.getHeight());
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:9,代碼來源:DropDownButton.java

示例10: subscribeActual

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
@Override
protected void subscribeActual(Observer<? super PopupMenuEvent> observer) {
    JPopupMenu w = widget;

    PopupMenuEventConsumer aec = new PopupMenuEventConsumer(observer, w);
    observer.onSubscribe(aec);

    w.addPopupMenuListener(aec);
    if (aec.get() == null) {
        aec.onDispose(w);
    }
}
 
開發者ID:akarnokd,項目名稱:RxJava2Swing,代碼行數:13,代碼來源:PopupMenuEventPopupObservable.java

示例11: PopupPanel

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
public PopupPanel(JPopupMenu popup)
{
	this.popup = popup;
	this.mapping = new HashMap<Locale, JTextComponent>();

	setLayout(new MigLayout("wrap,fill", "[grow]r[]", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
	for( Locale locale : editableLocales )
	{
		String actionCommand = locale.toString();
		JTextComponent field = getTextComponent();

		JButton button = new JButton(locale.getDisplayName());
		button.setActionCommand(actionCommand);
		button.addActionListener(this);

		field.setText(textMap.get(locale));
		mapping.put(locale, field);

		add(prepareTextComponent(field), "growx, sizegroup f, hmax 100px"); //$NON-NLS-1$
		add(button, "sizegroup b"); //$NON-NLS-1$
	}

	closeButton = new JLinkButton(CurrentLocale.get("prompts.close")); //$NON-NLS-1$
	closeButton.addActionListener(this);
	closeButton.setActionCommand(""); //$NON-NLS-1$
	closeButton.setIcon(new ArrowIcon(SwingConstants.NORTH));
	closeButton.setHorizontalTextPosition(SwingConstants.LEFT);
	add(closeButton, "span 2, align right, shrink"); //$NON-NLS-1$

	setBorder(BorderFactory.createLineBorder(Color.BLACK));

	final int width = Math.max(400, I18nTextField.this.getSize().width);
	setPreferredSize(new Dimension(width, getPreferredSize().height));

	popup.addPopupMenuListener(this);
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:37,代碼來源:I18nTextField.java

示例12: showPopupMenu

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
public void showPopupMenu(JPopupMenu menu, int x, int y) {
	double zoom = getZoomFactor();
	if (zoom != 1.0) {
		x = (int) Math.round(x * zoom);
		y = (int) Math.round(y * zoom);
	}
	myListener.menu_on = true;
	menu.addPopupMenuListener(myListener);
	menu.show(this, x, y);
}
 
開發者ID:LogisimIt,項目名稱:Logisim,代碼行數:11,代碼來源:Canvas.java

示例13: initializePopup

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
protected void initializePopup() {
    popup = new JPopupMenu();
    popup.setLayout(new BorderLayout());
    popup.setBorder(new EmptyBorder(0, 0, 0, 0));
    popup.addPopupMenuListener(this);
    popup.add(scroller);
    popup.pack();
}
 
開發者ID:bcgov,項目名稱:sbc-qsystem,代碼行數:9,代碼來源:JTreeComboBox.java

示例14: getToolbarPresenter

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
@Override public Component getToolbarPresenter() {
    JPopupMenu menu = new JPopupMenu();
    JButton button = DropDownButtonFactory.createDropDownButton(
            new ImageIcon(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)), menu);
    final JMenuItem item = new JMenuItem(Actions.cutAmpersand((String) delegate.getValue("menuText")));
    item.setEnabled(delegate.isEnabled());

    delegate.addPropertyChangeListener(new PropertyChangeListener() {
        @Override public void propertyChange(PropertyChangeEvent evt) {
            String propName = evt.getPropertyName();
            if ("enabled".equals(propName)) {
                item.setEnabled((Boolean)evt.getNewValue());
            } else if ("menuText".equals(propName)) {
                item.setText(Actions.cutAmpersand((String) evt.getNewValue()));
            } else if ("selectedProjects".equals(propName)) {
                Project[] projects = (Project[]) evt.getNewValue();
                if (projects.length == 1) {
                    debugHistorySupport.setSelectedProject(projects[0].getProjectDirectory());
                } else {
                    debugHistorySupport.setSelectedProject(null);
                }
            }
        }
    });

    menu.add(item);
    item.addActionListener(new ActionListener() {
        @Override public void actionPerformed(ActionEvent e) {
            DebugMainProjectAction.this.actionPerformed(e);
        }
    });
    try {
        Action ca = Actions.forID("Debug", "org.netbeans.modules.debugger.ui.actions.ConnectAction");
        JMenuItem item2 = new JMenuItem(Actions.cutAmpersand((String) ca.getValue(NAME)));
        Actions.connect(item2, ca);
        menu.add(item2);
    } catch (Exception nsee) {
        Exceptions.printStackTrace(nsee);
    }

    menu.addPopupMenuListener(this);

    Actions.connect(button, this);
    return button;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:46,代碼來源:DebugMainProjectAction.java


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