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


Java JPopupMenu.isVisible方法代碼示例

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


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

示例1: main

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
public static void main(String[] args) {
    Robot r = Util.createRobot();
    JWindow w = new JWindow();
    w.setSize(100, 100);
    w.setVisible(true);
    Util.waitForIdle(r);

    final JPopupMenu menu = new JPopupMenu();
    JButton item = new JButton("A button in popup");

    menu.add(item);

    w.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
            menu.show(me.getComponent(), me.getX(), me.getY());

            System.out.println("Showing menu at " + menu.getLocationOnScreen() +
                               " isVisible: " + menu.isVisible() +
                               " isValid: " + menu.isValid());
            }
        });

    Util.clickOnComp(w, r);
    Util.waitForIdle(r);

    if (!menu.isVisible()) {
        throw new RuntimeException("menu was not shown");
    }

    menu.hide();
    System.out.println("Test passed.");
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:33,代碼來源:GrabOnUnfocusableToplevel.java

示例2: TestPopupMenu

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
public TestPopupMenu() throws Exception {
    Robot robot = new Robot();
    robot.setAutoDelay(200);
    try {
        SwingUtilities.invokeAndWait(() -> {
            try {
                createAndShowUI();
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        });
        blockTillDisplayed(label);
        robot.waitForIdle();
        robot.mouseMove(p.x + d.width/2, p.y + d.height/2);
        robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
        robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
        robot.waitForIdle();
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_U);
        robot.keyRelease(KeyEvent.VK_U);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        robot.waitForIdle();
        JPopupMenu popup = label.getComponentPopupMenu();
        if (popup != null && popup.isVisible()) {
            throw new RuntimeException("Popup is visible in wrong internal frame");
        }
    } finally {
        SwingUtilities.invokeAndWait(()->frame.dispose());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:31,代碼來源:TestPopupMenu.java

示例3: actionPerformed

import javax.swing.JPopupMenu; //導入方法依賴的package包/類
@Override
public void actionPerformed(ActionEvent ae) {
  int index = -1;
  if (highlightedChainAnnotsOffsets != null) {
    for (int i = 0; i < highlightedChainAnnotsOffsets.length; i += 2) {
      if (textLocation >= highlightedChainAnnotsOffsets[i] &&
          textLocation <= highlightedChainAnnotsOffsets[i + 1]) {
        index = (i == 0) ? i : i / 2;
        break;
      }
    }
  }

  // yes it is put on highlighted so show the annotationType
  if (highlightedChainAnnotsOffsets != null &&
      index < highlightedChainAnnotsOffsets.length && index >= 0) {
    return;
  }

  if (highlightedTypeAnnotsOffsets != null) {
    for (int i = 0; i < highlightedTypeAnnotsOffsets.length; i += 2) {
      if (textLocation >= highlightedTypeAnnotsOffsets[i] &&
          textLocation <= highlightedTypeAnnotsOffsets[i + 1]) {
        index = (i == 0) ? i : i / 2;
        break;
      }
    }
  }

  // yes it is put on highlighted so show the annotationType
  if (highlightedTypeAnnotsOffsets != null &&
      index < highlightedTypeAnnotsOffsets.length && index >= 0) {
    textPane.removeAll();
    annotToConsiderForChain = highlightedTypeAnnots.get(index);
    // now check if this annotation is already linked with something
    CorefTreeNode headNode = findOutTheChainHead(annotToConsiderForChain, (String) annotSets.getSelectedItem());
    if (headNode != null) {
      popup1 = new JPopupMenu();
      popup1.setBackground(UIManager.getLookAndFeelDefaults().
                           getColor("ToolTip.background"));
      JLabel label1 = new JLabel("Annotation co-referenced to : \"" +
                                 headNode.toString() + "\"");
      popup1.setLayout(new FlowLayout());
      popup1.add(label1);
      if (popupWindow != null && popupWindow.isVisible()) {
        popupWindow.setVisible(false);
      }
      popup1.setVisible(true);
      popup1.show(textPane, (int) mousePoint.getX(), (int) mousePoint.getY());
    }
    else {
      popupWindow.setVisible(false);
      List<String> set = new ArrayList<String>(currentSelections.keySet());
      Collections.sort(set);
      set.add(0, "[New Chain]");
      model = new DefaultComboBoxModel<String>(set.toArray(new String[set.size()]));
      list.setModel(model);
      listEditor.setItem("");
      label.setText("Add \"" + getString(annotToConsiderForChain) +
                    "\" to ");
      Point topLeft = textPane.getLocationOnScreen();
      int x = topLeft.x + (int) mousePoint.getX();
      int y = topLeft.y + (int) mousePoint.getY();
      popupWindow.setLocation(x, y);
      if (popup1.isVisible()) {
        popup1.setVisible(false);
      }
      popupWindow.pack();
      popupWindow.setVisible(true);
      listEditor.requestFocus();

      if (firstTime) {
        firstTime = false;
        popupWindow.pack();
        popupWindow.repaint();
        listEditor.requestFocus();
      }
    }
  }
}
 
開發者ID:GateNLP,項目名稱:gate-core,代碼行數:81,代碼來源:CorefEditor.java


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