Java Code Examples for javax.swing.JPopupMenu#setVisible()
The following examples show how to use
javax.swing.JPopupMenu#setVisible() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ButtonPopupSwitcher.java From netbeans with Apache License 2.0 | 6 votes |
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(); }
Example 2
Source File: ButtonPopupSwitcher.java From netbeans with Apache License 2.0 | 6 votes |
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(); }
Example 3
Source File: JPopupMenuUtils.java From netbeans with Apache License 2.0 | 5 votes |
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); } }
Example 4
Source File: JPopupMenuUtils.java From netbeans with Apache License 2.0 | 4 votes |
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); } }
Example 5
Source File: EditorUI.java From netbeans with Apache License 2.0 | 4 votes |
public void hidePopupMenu() { JPopupMenu pm = getPopupMenu(); if (pm != null) { pm.setVisible(false); } }
Example 6
Source File: CorefEditor.java From gate-core with GNU Lesser General Public License v3.0 | 4 votes |
@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(); } } } }
Example 7
Source File: RosterDialog.java From Spark with Apache License 2.0 | 4 votes |
/** * 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); } } }