javax.swing.JPopupMenu.setLocation()方法的使用及代码示例

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

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

JPopupMenu.setLocation介绍

暂无

代码示例

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

private void showPopupMenu(Component callingComponent, String actionCommand) {
    // Get the location of the point 'on the screen'
    Point p = callingComponent.getLocationOnScreen();
    // Show the JPopupMenu via program
    // Parameter desc
    // ----------------
    // this - represents current frame
    // 0,0 is the co ordinate where the popup
    // is shown
    JPopupMenu menu;
    if (actionCommand.endsWith("Yes")) {
      menu = popupMenuAskYes;
    } else {
      menu = popupMenuAskNo;
    }
    menu.show(this, 0, 0);

    // Now set the location of the JPopupMenu
    // This location is relative to the screen
    menu.setLocation(p.x, p.y + callingComponent.getHeight());
  }
}

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

@Override
  public void mouseReleased(MouseEvent evt) {
    if (evt.isPopupTrigger()) {
      // Fix #45348: IllegalComponentStateException on show()
      try {
        menu.show(evt.getComponent(), evt.getX(), evt.getY());
      } catch (IllegalComponentStateException e) {
        LOGGER.error(e, e);
      }
      
      menu.setLocation(
        ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT
        ? evt.getXOnScreen() - menu.getWidth()
        : evt.getXOnScreen(),
        evt.getYOnScreen()
      );
    }
  }
});

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

@Override
  public void mousePressed(MouseEvent e) {
    popup.applyComponentOrientation(ComponentOrientation.getOrientation(I18n.getLocaleDefault()));
    if (ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT) {
      radioCustomMethod.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 6));
    } else {
      radioCustomMethod.setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 0));
    }
    
    popup.show(
      e.getComponent(),
      ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT
      ? e.getComponent().getX() - e.getComponent().getWidth() - popup.getWidth()
      : e.getComponent().getX(),
      e.getComponent().getY() + e.getComponent().getWidth()
    );
    
    popup.setLocation(
      ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT
      ? e.getComponent().getLocationOnScreen().x + e.getComponent().getWidth() - popup.getWidth()
      : e.getComponent().getLocationOnScreen().x,
      e.getComponent().getLocationOnScreen().y + e.getComponent().getWidth()
    );
  }
});

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

@Override
public void mouseClicked(MouseEvent e) {
  if (SwingUtilities.isRightMouseButton(e)) {
    Component componentSource = (Component) e.getSource();
    JPopupMenu menu = new JPopupMenu();
    for (int position = 0 ; position < MediatorGui.menubar().getMenuView().getMenuComponentCount() ; position++) {
      // Fix #35348: SerializationException on clone()
      try {
        JMenuItem itemMenu = (JMenuItem) SerializationUtils.clone(MediatorGui.menubar().getMenuView().getMenuComponent(position));
        menu.add(itemMenu);
        
        final int positionFinal = position;
        itemMenu.addActionListener(actionEvent -> MediatorGui.tabManagers().setSelectedIndex(positionFinal));
      } catch (SerializationException ex) {
        LOGGER.error(ex, ex);
      }
    }
    menu.show(componentSource, e.getX(), e.getY());
    
    menu.setLocation(
      ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT
      ? e.getXOnScreen() - menu.getWidth()
      : e.getXOnScreen(),
      e.getYOnScreen()
    );
  }
}

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

popupMenuList.setLocation(
  ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT
  ? mouseEvent.getXOnScreen() - popupMenuList.getWidth()

代码示例来源:origin: org.netbeans.api/org-openide-awt

private void displayOverflow() {
  int x = getOrientation() == HORIZONTAL ? overflowButton.getLocationOnScreen().x : overflowButton.getLocationOnScreen().x + overflowButton.getWidth();
  int y = getOrientation() == HORIZONTAL ? overflowButton.getLocationOnScreen().y + overflowButton.getHeight() : overflowButton.getLocationOnScreen().y;
  popup.setLocation(x, y);
  popup.setVisible(true);
}

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

super.setMenuLocation(x, y);
if(popupMenu != null) {
  popupMenu.setLocation(x, y);

代码示例来源:origin: edu.toronto.cs.medsavant/medsavant-client

@Override
public void setMenuLocation(int x, int y) {
  super.setMenuLocation(x, y);
  if(popupMenu != null) {
    popupMenu.setLocation(x, y);
  }
}

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

final TrayIcon tray = new TrayIcon( img, tooltip, null);
final JPopupMenu menu = new JPopupMenu();
... // your menu initialization.
tray.addMouseListener( new MouseAdapter() {
  @Override
  public void mouseClicked(MouseEvent evt) {
    menu.setLocation( evt.getPoint() );
    menu.setVisible( true );
  }
}

代码示例来源:origin: org.geotools/gt-widgets-swing-pending

private void actionMenu(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actionMenu
  JPopupMenu menu = new JPopupMenu();
  menu.setLocation( jbu_action.getLocationOnScreen().x, jbu_action.getLocationOnScreen().y);
  
  JMenuItem mi = new JMenuItem("test");
  menu.add(mi);
  
  //menu.setVisible(true);
      
}//GEN-LAST:event_actionMenu

代码示例来源:origin: org.appdapter/org.appdapter.lib.gui

private void showSubMenuPopup(MouseEvent event, Object valueAtTip, Container from) {
  JPopupMenu tpm = TriggerMenuFactory.buildPopupMenuAndShow(event, false, valueAtTip);
  tpm.setLocation((int) event.getLocationOnScreen().getX(), (int) event.getLocationOnScreen().getY());
  tpm.show();
}

代码示例来源:origin: com.jidesoft/jide-oss

@Override
public void setLocation(int x, int y) {
  // TODO: this is really a hack. Two classes will call this method. One is when the JPopupMenu is show. The other
  if (isVisible() && y <= 0) {
    move(x, y); // cannot call setLocation because it will be recursive call. So call deprecated move in order to bypass this.
  }
  else {
    super.setLocation(x, y);
  }
}

代码示例来源:origin: net.sf.squirrel-sql.plugins/graph

public void showPopupAbove(Point loc, GraphControllerPopupListener graphControllerPopupListener)
{
 if (_popUp.isVisible())
 {
   _popUp.setVisible(false);
 }
 else
 {
   _popUp.show(_desktopPane,0,0);
   _popUp.setLocation(loc.x, loc.y - _popUp.getHeight());
 }
 _currentGraphControllerPopupListener = graphControllerPopupListener;
}

代码示例来源:origin: edu.toronto.cs.savant/savant-core

public static void showPopup(PopupHostingAdapter parent, Point globalPt, Track t, Record overRecord) {
  JPopupMenu jp = new JPopupMenu();
  PopupPanel pp = create(parent, t.getDrawingMode(), t.getDataSource(), overRecord);
  parent.firePopupEvent(pp);
  if (pp != null) {
    jp.setLayout(new BorderLayout());
    jp.add(pp, BorderLayout.CENTER);
    jp.setLocation(globalPt.x - 2, globalPt.y - 2);
    activePopup = jp;
    activeHost = parent;
    jp.setVisible(true);
  }
}

代码示例来源:origin: org.fosstrak.hal/hal-impl-sim

public void mouseReleased(MouseEvent e) {
  hideActiveContextMenuAndSelection();
  if (e.getButton() == MouseEvent.BUTTON3) {
    Point posOnScreen = getJLayeredPane().getLocationOnScreen();
    contextMenu.setLocation(posOnScreen.x + e.getX(), posOnScreen.y + e.getY());
    contextMenu.setVisible(true);
    setActiveContextMenu(contextMenu);
  } else {
    contextMenu.setVisible(false);
    if(e.getButton() == MouseEvent.BUTTON1) {
      selection.select(tags);
    }
  }
}

代码示例来源:origin: sc.fiji/Simple_Neurite_Tracer

@Override
  public void actionPerformed(final ActionEvent e) {
    if (!swcTypesMenu.isVisible()) {
      final Point p = swcTypesButton.getLocationOnScreen();
      swcTypesMenu.setInvoker(swcTypesButton);
      swcTypesMenu.setLocation((int) p.getX(), (int) p.getY() + swcTypesButton.getHeight());
      swcTypesMenu.setVisible(true);
    } else {
      swcTypesMenu.setVisible(false);
    }
  }
});

代码示例来源:origin: uk.ac.ebi.caf/caf-report

@Override
  public void mouseClicked(MouseEvent e) {
    if (e.getButton() == MouseEvent.BUTTON3) {
      Point mouse = MouseInfo.getPointerInfo().getLocation();
      menu.setLocation(mouse.x + 20, mouse.y - 20);
      menu.setVisible(!menu.isVisible());
    } else {
      menu.setVisible(false);
    }
  }
}

代码示例来源:origin: net.java.openjdk.cacio/cacio-shared

public void show(Event e) {
  JMenu m = (JMenu) getSwingMenu();
  JPopupMenu pm = m.getPopupMenu();
  Dimension d = pm.getPreferredSize();
  // TODO: Fix location relative to target.
  pm.setLocation(e.x, e.y);
  pm.setSize(d.width, d.height);
  pm.setVisible(true);
  // TODO: Add listener for closing the popup menu.
}

代码示例来源:origin: com.eas.platypus/platypus-js-forms

@ScriptFunction
@Override
public void setLeft(int aValue) {
  if (super.getParent() != null && super.getParent().getLayout() instanceof MarginLayout) {
    MarginLayout.ajustLeft(this, aValue);
  }
  super.setLocation(aValue, getTop());
}

代码示例来源:origin: com.eas.platypus/platypus-js-forms

@ScriptFunction
@Override
public void setTop(int aValue) {
  if (super.getParent() != null && super.getParent().getLayout() instanceof MarginLayout) {
    MarginLayout.ajustTop(this, aValue);
  }
  super.setLocation(getLeft(), aValue);
}

相关文章

JPopupMenu类方法