javax.swing.JPopupMenu#setVisible ( )源码实例Demo

下面列出了javax.swing.JPopupMenu#setVisible ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: ButtonPopupSwitcher.java
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 项目: netbeans   文件: ButtonPopupSwitcher.java
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 项目: netbeans   文件: JPopupMenuUtils.java
public static void dynamicChange(final JPopupMenu popup, boolean usedToBeContained) {
        if (!popup.isShowing()) {
            return;
        }

        if (isProblemConfig()) {
            callRefreshLater(popup);

            return;
        }

        refreshPopup(popup);

        Point p = popup.getLocationOnScreen();
        Point newPt = getPopupMenuOrigin(popup, p);

        boolean willBeContained = willPopupBeContained(popup, newPt);

        if (usedToBeContained != willBeContained) {
            popup.setVisible(false);
        }

        if (!newPt.equals(p)) {
//            if (!NO_POPUP_PLACEMENT_HACK) {
//                popup.setLocation(newPt.x, newPt.y);
//            }
        }

        if (usedToBeContained != willBeContained) {
            popup.setVisible(true);
        }
    }
 
源代码4 项目: netbeans   文件: JPopupMenuUtils.java
public static void dynamicChangeToSubmenu(JPopupMenu popup, boolean usedToBeContained) {
    Object invoker = popup.getInvoker();

    if (!(invoker instanceof JMenu)) {
        return;
    }

    JMenu menu = (JMenu) invoker;

    if (!popup.isShowing()) {
        return;
    }

    if (isProblemConfig()) {
        callRefreshLater2(popup, menu);

        return;
    }

    refreshPopup(popup);

    Point p = popup.getLocationOnScreen();
    Dimension popupSize = popup.getPreferredSize();
    Rectangle popupRect = new Rectangle(p, popupSize);
    Rectangle screenRect = getScreenRect();
    boolean willBeContained = isPopupContained(popup);

    if (!screenRect.contains(popupRect)) {
        /*
         * The menu grew off the edge of the screen.
         */
        menu.setPopupMenuVisible(false);
        menu.setPopupMenuVisible(true);
    } else if (usedToBeContained != willBeContained) {
        /*
         * The menu grew off the edge of the containing window.
         * Use the setVisible() hack to change the menu from
         * lightweight to heavyweight.
         */
        popup.setVisible(false);
        popup.setVisible(true);
    }
}
 
源代码5 项目: netbeans   文件: EditorUI.java
public void hidePopupMenu() {
    JPopupMenu pm = getPopupMenu();
    if (pm != null) {
        pm.setVisible(false);
    }
}
 
源代码6 项目: gate-core   文件: CorefEditor.java
@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();
      }
    }
  }
}
 
源代码7 项目: Spark   文件: RosterDialog.java
/**
    * Creates a Popupdialog above the Search Button displaying matching
    * Contacts
    * 
    * @param byname
    *            , the Searchname, atleast 5 Chars long
    * @param event
    *            , the MouseEvent which triggered it
    * @throws XMPPException
    * @throws InterruptedException 
    */
   public void searchForContact(String byname, MouseEvent event)
           throws XMPPException, SmackException.NotConnectedException, SmackException.NoResponseException, InterruptedException
   {

   	UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
   	
if (byname.contains("@")) {
    byname = byname.substring(0, byname.indexOf("@"));
}

if (byname.length() <= 1) {
    JOptionPane.showMessageDialog(jidField,
	    Res.getString("message.search.input.short"),
	    Res.getString("title.notification"),
	    JOptionPane.ERROR_MESSAGE);

} else {

    JPopupMenu popup = new JPopupMenu();
    JMenuItem header = new JMenuItem(
	    Res.getString("group.search.results") + ":");
    header.setBackground(UIManager.getColor("List.selectionBackground"));
    header.setForeground(Color.red);
    popup.add(header);

    for (DomainBareJid search : _usersearchservice) {

	ReportedData data;
	UserSearchManager usersearchManager = new UserSearchManager(
		SparkManager.getConnection());

	Form f = usersearchManager.getSearchForm(search);

	Form answer = f.createAnswerForm();
	answer.setAnswer("Name", true);
	answer.setAnswer("Email", true);
	answer.setAnswer("Username", true);
	answer.setAnswer("search", byname);

	data = usersearchManager.getSearchResults(answer, search);

	ArrayList<String> columnnames = new ArrayList<>();
	for ( ReportedData.Column column : data.getColumns() ) {
	    String label = column.getLabel();
	    columnnames.add(label);
	}

	for (ReportedData.Row row : data.getRows() ) {
	    if (!row.getValues(columnnames.get(0)).isEmpty()) {
		String s = row.getValues(columnnames.get(0))
			.get(0).toString();
		final JMenuItem item = new JMenuItem(s);
		popup.add(item);
		item.addActionListener( e -> {
           jidField.setText(item.getText());
           nicknameField.setText(XmppStringUtils
               .parseLocalpart(item.getText()));
           } );
	    }

	}
    }

    if (popup.getComponentCount() > 2) {
	popup.setVisible(true);
	popup.show(_searchForName, event.getX(), event.getY());
    } else if (popup.getComponentCount() == 2) {
	jidField.setText(((JMenuItem) popup.getComponent(1)).getText());
	nicknameField.setText(XmppStringUtils.parseLocalpart(((JMenuItem) popup
		.getComponent(1)).getText()));
    } else {
	JOptionPane.showMessageDialog(jidField,
		Res.getString("message.no.results.found"),
		Res.getString("title.notification"),
		JOptionPane.ERROR_MESSAGE);
    }
}
   }