javax.swing.JPopupMenu类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(143)

本文整理了Java中javax.swing.JPopupMenu类的一些代码示例,展示了JPopupMenu类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JPopupMenu类的具体详情如下:
包路径:javax.swing.JPopupMenu
类名称:JPopupMenu

JPopupMenu介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

final JFrame frame = new JFrame(TestTableRightClick.class.getSimpleName());
Vector<String> columns = new Vector<String>(Arrays.asList("Name", "Age"));
Vector<Vector<String>> data = new Vector<Vector<String>>();
final JPopupMenu popupMenu = new JPopupMenu();
JMenuItem deleteItem = new JMenuItem("Delete");
deleteItem.addActionListener(new ActionListener() {
popupMenu.add(deleteItem);
table.setComponentPopupMenu(popupMenu);
frame.add(new JScrollPane(table), BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);

代码示例来源:origin: stanfordnlp/CoreNLP

private void maybeShowPopup(MouseEvent e) {
 if (e.isPopupTrigger())
  treePopup.show(e.getComponent(), e.getX(), e.getY());
}

代码示例来源:origin: skylot/jadx

private JPopupMenu createTabPopupMenu(final ContentPanel contentPanel) {
  JPopupMenu menu = new JPopupMenu();
    JMenuItem copyRootClassName = new JMenuItem(NLS.str("tabs.copy_class_name"));
    copyRootClassName.addActionListener(actionEvent -> copyRootClassName());
    menu.add(copyRootClassName);
    menu.addSeparator();
  JMenuItem closeTab = new JMenuItem(NLS.str("tabs.close"));
  closeTab.addActionListener(e -> closeCodePanel(contentPanel));
  menu.add(closeTab);
    menu.add(closeOther);
    JMenuItem closeAll = new JMenuItem(NLS.str("tabs.closeAll"));
    closeAll.addActionListener(e -> closeAllTabs());
    menu.add(closeAll);
    menu.addSeparator();
      item.addActionListener(e -> setSelectedComponent(cp));
      item.setIcon(node.getIcon());
      menu.add(item);

代码示例来源:origin: skylot/jadx

void addPopupItems() {
  popup.add(undoAction);
  popup.add(redoAction);
  popup.addSeparator();
  popup.add(cutAction);
  popup.add(copyAction);
  popup.add(pasteAction);
  popup.add(deleteAction);
  popup.addSeparator();
  popup.add(selectAllAction);
}

代码示例来源:origin: skylot/jadx

private void addMenuItems(JClass jCls) {
  Action findUsage = new FindUsageAction(contentPanel, this, jCls);
  JPopupMenu popup = getPopupMenu();
  popup.addSeparator();
  popup.add(findUsage);
  popup.addPopupMenuListener((PopupMenuListener) findUsage);
}

代码示例来源:origin: log4j/log4j

protected void showPopup(CategoryNode node, int x, int y) {
 JPopupMenu popup = new JPopupMenu();
 popup.setSize(150, 400);
 //
 // Configure the Popup
 //
 if (node.getParent() == null) {
  popup.add(createRemoveMenuItem());
  popup.addSeparator();
 }
 popup.add(createSelectDescendantsMenuItem(node));
 popup.add(createUnselectDescendantsMenuItem(node));
 popup.addSeparator();
 popup.add(createExpandMenuItem(node));
 popup.add(createCollapseMenuItem(node));
 popup.addSeparator();
 popup.add(createPropertiesMenuItem(node));
 popup.show(_renderer, x, y);
}

代码示例来源:origin: igniterealtime/Smack

private void createDebug() {
  frame = new JFrame("Smack Debug Window");
    frame.addWindowListener(new WindowAdapter() {
      @Override
      public void windowClosing(WindowEvent evt) {
  JPopupMenu menu = new JPopupMenu();
  JMenuItem menuItem = new JMenuItem("Close");
  menuItem.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
  menu.add(menuItem);
  menuItem = new JMenuItem("Close All Not Active");
  menuItem.addActionListener(new ActionListener() {
    @Override
  menu.add(menuItem);
  frame.getContentPane().add(tabbedPane);
  frame.setSize(650, 400);

代码示例来源:origin: stackoverflow.com

final JFrame frame = new JFrame();
frame.setPreferredSize(new Dimension(600, 400));
final JToolBar toolBar = new JToolBar();
final JPopupMenu popup = new JPopupMenu();
popup.add(new JMenuItem(new AbstractAction("Option 1") {
  public void actionPerformed(ActionEvent e) {
    JOptionPane.showMessageDialog(frame, "Option 1 selected");
popup.add(new JMenuItem(new AbstractAction("Option 2") {
  public void actionPerformed(ActionEvent e) {
    JOptionPane.showMessageDialog(frame, "Option 2 selected");
button.addMouseListener(new MouseAdapter() {
  public void mousePressed(MouseEvent e) {
    popup.show(e.getComponent(), e.getX(), e.getY());
toolBar.add(button);
frame.getContentPane().add(toolBar, BorderLayout.NORTH);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);

代码示例来源:origin: stackoverflow.com

import javax.swing.*;
import java.awt.event.*;

public class Test {

  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setSize(400, 400);
    frame.setVisible(true);
    String[] list = {"1", "2", "3", "4",};
    JComboBox comb = new JComboBox(list);
    final JPopupMenu pop = new JPopupMenu();
    pop.add(comb);
    frame.addMouseListener(new MouseAdapter() {

      @Override
      public void mousePressed(MouseEvent e) {
        System.out.println("mousePressed");
        pop.show(e.getComponent(), e.getX(), e.getY());
      }
    });
  }
}

代码示例来源:origin: tomighty/tomighty

public JPopupMenu create(Action[] items) {
  JPopupMenu menu = new JPopupMenu();
  if(items != null && items.length > 0) {
    for(Action action : items) {
      injector.injectMembers(action);
      JMenuItem item = new JMenuItem(action);
      menu.add(item);
    }
    menu.addSeparator();
  }
  JMenu pluginsMenu = new JMenu(messages.get("Plugins"));
  pluginsMenu.add(menuItem("Manage", injector.getInstance(ShowPluginManager.class)));
  menu.add(menuItem("Options", injector.getInstance(ShowOptions.class)));
  menu.add(pluginsMenu);
  menu.add(menuItem("About", injector.getInstance(ShowAboutWindow.class)));
  menu.addSeparator();
  menu.add(menuItem("Close", new Exit()));
  return menu;
}

代码示例来源:origin: stackoverflow.com

popup = new JPopupMenu();
popup.add( new JMenuItem("Do Something1") );
popup.add( new JMenuItem("Do Something2") );
popup.add( new JMenuItem("Do Something3") );
JMenuItem menuItem = new JMenuItem("ActionPerformed");
menuItem.addActionListener( this );
popup.add( menuItem );
table.addMouseListener( new MouseAdapter()
    if (e.isPopupTrigger())
      int row = source.rowAtPoint( e.getPoint() );
      int column = source.columnAtPoint( e.getPoint() );
      popup.show(e.getComponent(), e.getX(), e.getY());
table.setPreferredScrollableViewportSize(table.getPreferredSize());
getContentPane().add( new JScrollPane(table) );
JPopupMenu popup = (JPopupMenu)c.getParent();
JTable table = (JTable)popup.getInvoker();
System.out.println(table.getSelectedRow() + " : " + table.getSelectedColumn());
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setLocationRelativeTo( null );
frame.setVisible( true );

代码示例来源:origin: stackoverflow.com

private JPopupMenu popup = new JPopupMenu("Hello World");
  JFrame frame = new JFrame("Button POP UP Example");
  frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  frame.setLocationByPlatform(true);
  contentPane.setLayout(new GridLayout(0, 5));
  JMenuItem menuItem1 = new JMenuItem("Menu Item 1");
  JMenuItem menuItem2 = new JMenuItem("Menu Item 2");
  popup.insert(menuItem1, 0);
  popup.insert(menuItem2, 1);
    button[i].setBorder(BorderFactory.createEtchedBorder());
    button[i].addMouseListener(new MouseAdapter()
        popup.show((JComponent)me.getSource(), me.getX(), me.getY());
    contentPane.add(button[i]);
  frame.getContentPane().add(contentPane);
  frame.setSize(175, 250);
  frame.setVisible(true);

代码示例来源:origin: stackoverflow.com

super(BoxLayout.Y_AXIS);
  final JPopupMenu menu = new JPopupMenu("Options");
  for(int i = 1; i < 20; i++)
    menu.add(new JMenuItem("Option" + i));
clickMe.setAlignmentX(RIGHT_ALIGNMENT);
  clickMe.addMouseListener(new MouseAdapter(){
      menu.show(e.getComponent(), e.getX(), e.getY());
    }});
  add(clickMe);       
  JFrame frame = new JFrame();
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setContentPane(new PopupMenu());
  frame.validate();
  frame.pack();
  frame.setVisible(true);

代码示例来源:origin: stackoverflow.com

public static void main ( String[] args )
{
  JFrame frame = new JFrame ();

  final JTree tree = new JTree ();
  tree.addMouseListener ( new MouseAdapter ()
  {
    public void mousePressed ( MouseEvent e )
    {
      if ( SwingUtilities.isRightMouseButton ( e ) )
      {
        TreePath path = tree.getPathForLocation ( e.getX (), e.getY () );
        Rectangle pathBounds = tree.getUI ().getPathBounds ( tree, path );
        if ( pathBounds != null && pathBounds.contains ( e.getX (), e.getY () ) )
        {
          JPopupMenu menu = new JPopupMenu ();
          menu.add ( new JMenuItem ( "Test" ) );
          menu.show ( tree, pathBounds.x, pathBounds.y + pathBounds.height );
        }
      }
    }
  } );
  frame.add ( tree );

  frame.pack ();
  frame.setLocationRelativeTo ( null );
  frame.setVisible ( true );
}

代码示例来源:origin: magefree/mage

private void showCardRightClickMenu(@SuppressWarnings("unused") final CardView card, MouseEvent e) {
  JPopupMenu menu = new JPopupMenu();
  JMenuItem hide = new JMenuItem("Hide");
  hide.addActionListener(e2 -> hideSelection());
  menu.add(hide);
  JMenuItem invertSelection = new JMenuItem("Invert Selection");
  invertSelection.addActionListener(e2 -> invertSelection());
  menu.add(invertSelection);
  JMenuItem chooseMatching = new JMenuItem("Choose Matching");
  chooseMatching.addActionListener(e2 -> chooseMatching());
  menu.add(chooseMatching);
  // Show 'Duplicate Selection' for FREE_BUILDING
  if (this.mode == Constants.DeckEditorMode.FREE_BUILDING) {
    JMenuItem duplicateSelection = new JMenuItem("Duplicate Selection");
    duplicateSelection.addActionListener(e2 -> duplicateSelection());
    menu.add(duplicateSelection);
  }
  menu.show(e.getComponent(), e.getX(), e.getY());
}

代码示例来源:origin: net.sf.ingenias/editor

public static void main(String args[]){
  JFrame jf=new JFrame();

  jf.getContentPane().add(new JLabel(ScrollableJPopupMenu.upIcon));
  jf.pack();
  jf.setLocation(200, 200);
  jf.setVisible(true);
  
  JPopupMenu jp=new ScrollableJPopupMenu(20);
  
  for (int k=0;k<50;k++)
  jp.add(new JMenuItem(new AbstractAction("hola"+k) {
    
    @Override
    public void actionPerformed(ActionEvent e) {
      System.out.println("hllo");
      
    }
  }));
  
  jp.add(new JMenu("adios"));
  jp.setLocation(200, 200);
  jp.setVisible(true);
  
}

代码示例来源:origin: stackoverflow.com

private final JPopupMenu popup = new JPopupMenu("Popup");
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  final JMenu menuB = new JMenu("B");
  menuB.add(new JMenuItem("X"));
  final JMenuItem menuY = menuB.add(new JMenuItem("Y"));
  menuB.add(new JMenuItem("Z"));
  popup.add(new JMenuItem("A"));
  popup.add(menuB);
  popup.add(new JMenuItem("C"));
    @Override
    public void actionPerformed(ActionEvent e) {
      popup.show(button, 0, button.getHeight());
  buttonPanel.add(button);
  getContentPane().add(buttonPanel);
  f.setSize(500, 300);
  f.setVisible(true);

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame();
 frame.setSize(300,300);
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 JPanel panel = new JPanel();
 JPopupMenu aaa = new JPopupMenu();
 JMenu mmm = new JMenu("mmm");
 JMenuItem b = new JMenuItem("b");
 JMenuItem c = new JMenuItem("c");
 JMenuItem d = new JMenuItem("d");
 JMenuItem k = new JMenuItem("k");
 mmm.add(b);
 mmm.add(c);
 mmm.add(d);
 mmm.add(k);
 aaa.add(mmm);
 panel.setComponentPopupMenu(aaa);
 frame.add(panel);
 frame.setVisible(true);

代码示例来源:origin: ron190/jsql-injection

JPopupMenu popupMenuList = new JPopupMenu();
I18nView.addComponentForKey("LIST_IMPORT_CONFIRM_TITLE", mnImport);
popupMenuList.add(mnNew);
popupMenuList.add(new JSeparator());
popupMenuList.add(mnCut);
popupMenuList.add(mnCopy);
popupMenuList.add(mnPaste);
popupMenuList.add(mnDelete);
popupMenuList.add(new JSeparator());
popupMenuList.add(mnSelectAll);
popupMenuList.add(new JSeparator());
popupMenuList.add(mnImport);
popupMenuList.add(mnExport);
popupMenuList.add(new JSeparator());
popupMenuList.add(mnRestoreDefault);
popupMenuList.applyComponentOrientation(ComponentOrientation.getOrientation(I18n.getLocaleDefault()));
  popupMenuList.show(
    list,
    ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT
    ? mouseEvent.getX() - popupMenuList.getWidth()
popupMenuList.setLocation(
  ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT
  ? mouseEvent.getXOnScreen() - popupMenuList.getWidth()

代码示例来源:origin: pentaho/mondrian

jToolBar1 = new javax.swing.JToolBar();
jToolBar2 = new javax.swing.JToolBar();
toolbarNewPopupMenu = new JPopupMenu();
toolbarNewButton = new javax.swing.JButton();
toolbarOpenButton = new javax.swing.JButton();
jSeparator3 = new javax.swing.JSeparator();
exitMenuItem = new javax.swing.JMenuItem();
windowMenu = new javax.swing.JMenu();
helpMenu = new javax.swing.JMenu();
editMenu = new javax.swing.JMenu();
getContentPane().add(desktopPane, java.awt.BorderLayout.CENTER);
toolbarNewPopupMenu.add(newSchemaMenuItem2);
toolbarNewPopupMenu.add(newQueryMenuItem2);
toolbarNewPopupMenu.add(newJDBCExplorerMenuItem2);
getContentPane().add(jToolBar1, java.awt.BorderLayout.NORTH);
fileMenu.setText(

相关文章

JPopupMenu类方法