本文整理汇总了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();
}
示例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();
}
示例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());
}
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
}
}
示例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());
}
示例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);
}
}
示例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);
}
示例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);
}
示例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();
}
示例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;
}