List of usage examples for javax.swing JPopupMenu JPopupMenu
public JPopupMenu()
JPopupMenu
without an "invoker". From source file:edu.ku.brc.af.ui.forms.IconViewObj.java
private void showContextMenu(MouseEvent e) { final FormDataObjIFace selection = iconTray.getSelectedValue(); if (selection instanceof ObjectAttachmentIFace<?>) { final File original = AttachmentUtils .getAttachmentFile(((ObjectAttachmentIFace) selection).getAttachment()); JPopupMenu popup = new JPopupMenu(); JMenuItem menuItem = new JMenuItem(UIRegistry.getResourceString("AttachmentUtils.OPEN_IN_EV")); menuItem.addActionListener(new ActionListener() { @Override//from www . j a v a 2 s.co m public void actionPerformed(ActionEvent actionEvent) { try { AttachmentUtils.openFile(original); } catch (Exception ex) { UIRegistry.showLocalizedMsg("AttachmentUtils.NEV_TITLE", "AttachmentUtils.NEV_MSG"); } } }); popup.add(menuItem); popup.show(e.getComponent(), e.getX(), e.getY()); } }
From source file:gdt.jgui.entity.folder.JFolderFacetOpenItem.java
/** * Get the popup menu for the child node of the facet node * in the digest view.//w ww.ja v a 2s . c o m * @return the popup menu. */ @Override public JPopupMenu getPopupMenu(final String digestLocator$) { JPopupMenu popup = new JPopupMenu(); try { Properties locator = Locator.toProperties(digestLocator$); final String encodedSelection$ = locator.getProperty(JEntityDigestDisplay.SELECTION); byte[] ba = Base64.decodeBase64(encodedSelection$); final String selection$ = new String(ba, "UTF-8"); // System.out.println("JFolderFacetOpenItem:getPopupMenu:selection:="+selection$); locator = Locator.toProperties(selection$); String nodeType$ = locator.getProperty(JEntityDigestDisplay.NODE_TYPE); if (JEntityDigestDisplay.NODE_TYPE_FACET_OWNER.equals(nodeType$)) { JMenuItem openItem = new JMenuItem("Open"); popup.add(openItem); openItem.setHorizontalTextPosition(JMenuItem.RIGHT); openItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Properties locator = Locator.toProperties(selection$); String entihome$ = locator.getProperty(Entigrator.ENTIHOME); String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); File file = new File(entihome$ + "/" + entityKey$); Desktop.getDesktop().open(file); } catch (Exception ee) { Logger.getLogger(JFieldsFacetOpenItem.class.getName()).info(ee.toString()); } } }); JMenuItem editItem = new JMenuItem("Edit"); popup.add(editItem); editItem.setHorizontalTextPosition(JMenuItem.RIGHT); editItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Properties locator = Locator.toProperties(selection$); String entihome$ = locator.getProperty(Entigrator.ENTIHOME); String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); JFolderPanel fp = new JFolderPanel(); String fpLocator$ = fp.getLocator(); fpLocator$ = Locator.append(fpLocator$, Entigrator.ENTIHOME, entihome$); fpLocator$ = Locator.append(fpLocator$, EntityHandler.ENTITY_KEY, entityKey$); JConsoleHandler.execute(console, fpLocator$); } catch (Exception ee) { Logger.getLogger(JFieldsFacetOpenItem.class.getName()).info(ee.toString()); } } }); } if (NODE_TYPE_FILE_NODE.equals(nodeType$)) { JMenuItem openItem = new JMenuItem("Open"); popup.add(openItem); openItem.setHorizontalTextPosition(JMenuItem.RIGHT); openItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Properties locator = Locator.toProperties(selection$); String filePath$ = locator.getProperty(JFolderPanel.FILE_PATH); File file = new File(filePath$); Desktop.getDesktop().open(file); } catch (Exception ee) { Logger.getLogger(JFieldsFacetOpenItem.class.getName()).info(ee.toString()); } } }); String filePath$ = locator.getProperty(JFolderPanel.FILE_PATH); final File file = new File(filePath$); if (isTextFile(file)) { JMenuItem editItem = new JMenuItem("Edit"); popup.add(editItem); editItem.setHorizontalTextPosition(JMenuItem.RIGHT); editItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { InputStream is = new FileInputStream(file); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] b = new byte[1024]; int bytesRead = 0; while ((bytesRead = is.read(b)) != -1) { bos.write(b, 0, bytesRead); } byte[] ba = bos.toByteArray(); is.close(); String text$ = new String(ba, "UTF-8"); JTextEditor te = new JTextEditor(); String teLocator$ = te.getLocator(); teLocator$ = Locator.append(teLocator$, Entigrator.ENTIHOME, entihome$); teLocator$ = Locator.append(teLocator$, JTextEditor.TEXT, text$); locator$ = Locator.append(locator$, JRequester.REQUESTER_ACTION, JFolderPanel.ACTION_EDIT_FILE); locator$ = Locator.append(locator$, JFolderPanel.FILE_PATH, file.getPath()); locator$ = Locator.append(locator$, BaseHandler.HANDLER_METHOD, "response"); locator$ = Locator.append(locator$, JEntityDigestDisplay.SELECTION, encodedSelection$); String requesterResponceLocator$ = Locator.compressText(locator$); teLocator$ = Locator.append(teLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR, requesterResponceLocator$); JConsoleHandler.execute(console, teLocator$); } catch (Exception ee) { Logger.getLogger(getClass().getName()).info(ee.toString()); } } }); } } return popup; } catch (Exception e) { Logger.getLogger(getClass().getName()).severe(e.toString()); return null; } }
From source file:br.upe.ecomp.dosa.view.mainwindow.MainWindowActions.java
private void createPopupMenus() { JMenuItem algorithmMenu = new JMenuItem("Change algorithm..."); algorithmMenu.addActionListener(new ActionListener() { @Override/*from ww w .ja v a2s. c o m*/ public void actionPerformed(ActionEvent event) { showUpdateAlgorithmDialog(UpdateAlgorithmDialogEnum.ALGORITHM); } }); popupAlgorithm = new JPopupMenu(); popupAlgorithm.add(algorithmMenu); JMenuItem problemMenu = new JMenuItem("Change problem..."); problemMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { showUpdateAlgorithmDialog(UpdateAlgorithmDialogEnum.PROBLEM); } }); popupProblem = new JPopupMenu(); popupProblem.add(problemMenu); JMenuItem stopConditionAddMenu = new JMenuItem("Add stop condition..."); stopConditionAddMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { showUpdateAlgorithmDialog(UpdateAlgorithmDialogEnum.STOP_CONDITIONS); } }); JMenuItem stopConditionRemoveMenu = new JMenuItem("Remove stop condition..."); stopConditionRemoveMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { StopCondition stopCondition = (StopCondition) ((ExtendedTreeNode) tree .getLastSelectedPathComponent()).getUserObject(); algorithm.getStopConditions().remove(stopCondition); createNodes(); } }); popupStopCondition = new JPopupMenu(); popupStopCondition.add(stopConditionAddMenu); popupStopCondition.add(stopConditionRemoveMenu); JMenuItem measurementMenu = new JMenuItem("Add meassurement..."); measurementMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { showUpdateAlgorithmDialog(UpdateAlgorithmDialogEnum.MEASUREMENTS); } }); JMenuItem measurementRemoveMenu = new JMenuItem("Remove meassurement..."); measurementRemoveMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { Measurement measurement = (Measurement) ((ExtendedTreeNode) tree.getLastSelectedPathComponent()) .getUserObject(); algorithm.getMeasurements().remove(measurement); createNodes(); } }); popupMeassurement = new JPopupMenu(); popupMeassurement.add(measurementMenu); popupMeassurement.add(measurementRemoveMenu); // Add listener to components that can bring up popup menus. MouseListener popupListener = new PopupListener(); tree.addMouseListener(popupListener); }
From source file:net.sf.jhylafax.addressbook.AddressBook.java
private void initializeContent() { horizontalSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); horizontalSplitPane.setBorder(GUIHelper.createEmptyBorder(5)); rootNode = new DefaultMutableTreeNode(); addressBookTreeModel = new DefaultTreeModel(rootNode); addressBookTree = new JTree(addressBookTreeModel); addressBookTree.setRootVisible(false); addressBookTree.setCellRenderer(new ContactCollectionCellRenderer()); horizontalSplitPane.add(new JScrollPane(addressBookTree)); JPanel contactPanel = new JPanel(); contactPanel.setLayout(new BorderLayout(0, 10)); horizontalSplitPane.add(contactPanel); DefaultFormBuilder builder = new DefaultFormBuilder( new FormLayout("min, 3dlu, min, 3dlu, pref:grow, 3dlu, min", "")); contactPanel.add(builder.getPanel(), BorderLayout.NORTH); searchTextField = new JTextField(10); EraseTextFieldAction eraseAction = new EraseTextFieldAction(searchTextField) { public void actionPerformed(ActionEvent event) { super.actionPerformed(event); filterAction.actionPerformed(event); };/*from ww w . j a v a2 s. c o m*/ }; builder.append(new TabTitleButton(eraseAction)); filterLabel = new JLabel(); builder.append(filterLabel); builder.append(searchTextField); GUIHelper.bindEnterKey(searchTextField, filterAction); builder.append(Builder.createButton(filterAction)); JPopupMenu tablePopupMenu = new JPopupMenu(); tablePopupMenu.add(Builder.createMenuItem(newAction)); tablePopupMenu.addSeparator(); tablePopupMenu.add(Builder.createMenuItem(editAction)); tablePopupMenu.addSeparator(); tablePopupMenu.add(Builder.createMenuItem(deleteAction)); contactTableModel = new AddressTableModel(); TableSorter sorter = new TableSorter(contactTableModel); contactTable = new ColoredTable(sorter); contactTableLayoutManager = new TableLayoutManager(contactTable); contactTableLayoutManager.addColumnProperties("displayName", "", 180, true); contactTableLayoutManager.addColumnProperties("company", "", 80, true); contactTableLayoutManager.addColumnProperties("faxNumber", "", 60, true); contactTableLayoutManager.initializeTableLayout(); contactPanel.add(new JScrollPane(contactTable), BorderLayout.CENTER); contactTable.setShowVerticalLines(true); contactTable.setShowHorizontalLines(false); contactTable.setAutoCreateColumnsFromModel(true); contactTable.setIntercellSpacing(new java.awt.Dimension(2, 1)); contactTable.setBounds(0, 0, 50, 50); contactTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); contactTable.getSelectionModel().addListSelectionListener(this); contactTable.addMouseListener(new PopupListener(tablePopupMenu)); contactTable.addMouseListener(new DoubleClickListener(new TableDoubleClickAction())); contactTable.setTransferHandler(new ContactTransferHandler()); contactTable.setDragEnabled(true); contactTable.setDefaultRenderer(String.class, new StringCellRenderer()); getContentPane().setLayout(new BorderLayout()); getContentPane().add(horizontalSplitPane, BorderLayout.CENTER); }
From source file:gdt.jgui.entity.webset.JWeblinkEditor.java
private void showPasswordMenu(MouseEvent e) { try {//from ww w.j a v a 2s.co m JPopupMenu passwordMenu = new JPopupMenu(); JMenuItem copyItem = new JMenuItem("Copy"); passwordMenu.add(copyItem); copyItem.setHorizontalTextPosition(JMenuItem.RIGHT); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { StringSelection stringSelection = new StringSelection(passwordField.getText()); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, JWeblinkEditor.this); } catch (Exception ee) { Logger.getLogger(getClass().getName()).info(ee.toString()); } } }); JMenuItem encodeItem = new JMenuItem("Encrypt/decrypt"); passwordMenu.add(encodeItem); encodeItem.setHorizontalTextPosition(JMenuItem.RIGHT); encodeItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { save(); JTextEncrypter te = new JTextEncrypter(); String teLocator$ = te.getLocator(); teLocator$ = Locator.append(teLocator$, Entigrator.ENTIHOME, entihome$); teLocator$ = Locator.append(teLocator$, JTextEditor.TEXT, passwordField.getText()); teLocator$ = Locator.append(teLocator$, JTextEditor.TEXT_TITLE, nameField.getText()); String weLocator$ = JWeblinkEditor.this.getLocator(); weLocator$ = Locator.append(weLocator$, BaseHandler.HANDLER_METHOD, "response"); weLocator$ = Locator.append(weLocator$, JRequester.REQUESTER_ACTION, ACTION_ENCODE_PASSWORD); teLocator$ = Locator.append(teLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR, Locator.compressText(weLocator$)); JConsoleHandler.execute(console, teLocator$); } catch (Exception ee) { Logger.getLogger(getClass().getName()).info(ee.toString()); } } }); passwordMenu.show(e.getComponent(), e.getX(), e.getY()); } catch (Exception ee) { Logger.getLogger(getClass().getName()).severe(ee.toString()); } }
From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java
protected void displayAddPopup(JButton src) { JPopupMenu p = new JPopupMenu(); Map<String, List<Series<?>>> series = sampler.getCategories(); for (Map.Entry<String, List<Series<?>>> e1 : series.entrySet()) { JMenu sm = new JMenu(e1.getKey()); for (final Series<?> s : e1.getValue()) { if (!enabled.contains(s.getKey())) { JMenuItem mi = new JMenuItem(s.getLabel()); mi.addActionListener(new ActionListener() { @Override// w ww . j ava 2 s . c o m public void actionPerformed(ActionEvent e) { enable(s); } }); sm.add(mi); } } p.add(sm); } p.show(src, 4, 4); }
From source file:brainflow.app.toplevel.BrainFlow.java
private MenuFactory createMenuFactory() { return new MenuFactory() { @Override//from www .j a v a 2 s . c om public JMenu createMenu() { return new JideMenu(); } @Override public JMenuItem createMenuItem() { return new JMenuItem(); } @Override public JCheckBoxMenuItem createCheckBoxMenuItem() { return new JCheckBoxMenuItem(); } @Override public JRadioButtonMenuItem createRadioButtonMenuItem() { return new JRadioButtonMenuItem(); } @Override public JPopupMenu createPopupMenu() { return new JPopupMenu(); } @Override public JMenuBar createMenuBar() { return new CommandMenuBar(); } }; }
From source file:it.cnr.icar.eric.client.ui.swing.RegistryObjectsTable.java
private void createPopup() { try {/*from w ww. jav a 2 s . c o m*/ JAXRClient client = RegistryBrowser.getInstance().getClient(); ConnectionImpl connection = (ConnectionImpl) client.getConnection(); boolean authenticated = connection.isAuthenticated(); // Create popup menu for table popup = new JPopupMenu(); if (editable) { editMenuItem = new JMenuItem(resourceBundle.getString("menu.edit")); } else { editMenuItem = new JMenuItem(resourceBundle.getString("menu.showDetails")); } popup.add(editMenuItem); removeMenuItem = new JMenuItem(resourceBundle.getString("menu.remove")); popup.add(removeMenuItem); saveMenuItem = new JMenuItem(resourceBundle.getString("menu.save")); popup.add(saveMenuItem); setStatusMenuItem = new JMenu(resourceBundle.getString("menu.setStatus")); Collection<?> statusTypeConcepts = getStatusTypeConcepts(); createMenuItemsForTaxonomyElements(setStatusMenuItem, statusTypeConcepts); popup.add(setStatusMenuItem); approveMenuItem = new JMenuItem(resourceBundle.getString("menu.approve")); popup.add(approveMenuItem); deprecateMenuItem = new JMenuItem(resourceBundle.getString("menu.deprecate")); popup.add(deprecateMenuItem); undeprecateMenuItem = new JMenuItem(resourceBundle.getString("menu.undeprecate")); popup.add(undeprecateMenuItem); browseMenuItem = new JMenuItem(resourceBundle.getString("menu.browse")); popup.add(browseMenuItem); exportMenuItem = new JMenuItem(resourceBundle.getString("menu.export")); popup.add(exportMenuItem); auditTrailMenuItem = new JMenuItem(resourceBundle.getString("menu.showAuditTrail")); popup.add(auditTrailMenuItem); showRegistryObjectMenuItem = new JMenuItem(resourceBundle.getString("menu.showRegistryObject")); popup.add(showRegistryObjectMenuItem); showRepositoryItemMenuItem = new JMenuItem(resourceBundle.getString("menu.showRepositoryItem")); showRepositoryItemMenuItem.setVisible(false); popup.add(showRepositoryItemMenuItem); editMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { editAction(); } }); removeMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { removeAction(); } }); saveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { saveAction(); } }); approveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { approveAction(); } }); deprecateMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { deprecateAction(); } }); undeprecateMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { undeprecateAction(); } }); browseMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { browseAction(); } }); exportMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { exportAction(); } }); auditTrailMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { auditTrailAction(); } }); showRegistryObjectMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { showRegistryObjectAction(); } }); showRepositoryItemMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { showRepositoryItemAction(); } }); // hide and disable, if not authenticated removeMenuItem.setVisible(authenticated); saveMenuItem.setVisible(authenticated); approveMenuItem.setVisible(authenticated); setStatusMenuItem.setVisible(authenticated); deprecateMenuItem.setVisible(authenticated); undeprecateMenuItem.setVisible(authenticated); removeMenuItem.setEnabled(authenticated); saveMenuItem.setEnabled(authenticated); approveMenuItem.setEnabled(authenticated); setStatusMenuItem.setEnabled(authenticated); deprecateMenuItem.setEnabled(authenticated); undeprecateMenuItem.setEnabled(authenticated); } catch (JAXRException e) { RegistryBrowser.displayError(e); } }
From source file:gdt.jgui.entity.webset.JWebsetFacetOpenItem.java
/** * Get the popup menu for the child node of the facet node * in the digest view./*from w ww. j a v a2s.c om*/ * @return the popup menu. */ @Override public JPopupMenu getPopupMenu(final String digestLocator$) { JPopupMenu popup = new JPopupMenu(); JMenuItem openItem = new JMenuItem("Open"); popup.add(openItem); openItem.setHorizontalTextPosition(JMenuItem.RIGHT); openItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { // System.out.println("JWebsetFacetOpenItem:open:digest locator="+digestLocator$); Properties locator = Locator.toProperties(digestLocator$); String encodedSelection$ = locator.getProperty(JEntityDigestDisplay.SELECTION); byte[] ba = Base64.decodeBase64(encodedSelection$); String selection$ = new String(ba, "UTF-8"); // System.out.println("JWebsetFacetOpenItem:open:selection="+selection$); locator = Locator.toProperties(selection$); String entihome$ = locator.getProperty(Entigrator.ENTIHOME); String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); String type$ = locator.getProperty(Locator.LOCATOR_TYPE); if (LOCATOR_TYPE_WEB_ADDRESS.equals(type$)) { try { String url$ = locator.getProperty(JWeblinksPanel.WEB_LINK_URL); // System.out.println("weblinkEditor:browseUrl:url="+url$); Desktop.getDesktop().browse(new URI(url$)); } catch (Exception ee) { Logger.getLogger(JFileOpenItem.class.getName()).info(ee.toString()); } return; } if (JEntityDigestDisplay.LOCATOR_FACET_COMPONENT.equals(type$)) { // String entityKey$=locator.getProperty(EntityHandler.ENTITY_KEY); JWeblinkEditor we = new JWeblinkEditor(); String weLocator$ = we.getLocator(); weLocator$ = Locator.append(weLocator$, Entigrator.ENTIHOME, entihome$); weLocator$ = Locator.append(weLocator$, EntityHandler.ENTITY_KEY, entityKey$); //JConsoleHandler.execute(console,beLocator$); return; } String weblinkKey$ = locator.getProperty(JWeblinksPanel.WEB_LINK_KEY); JWeblinkEditor we = new JWeblinkEditor(); String weLocator$ = we.getLocator(); weLocator$ = Locator.append(weLocator$, Entigrator.ENTIHOME, entihome$); weLocator$ = Locator.append(weLocator$, EntityHandler.ENTITY_KEY, entityKey$); weLocator$ = Locator.append(weLocator$, JWeblinksPanel.WEB_LINK_KEY, weblinkKey$); /* Entigrator entigrator=console.getEntigrator(entihome$); String componentKey$=locator.getProperty(JEntityDigestDisplay.COMPONENT_KEY); Sack entity=entigrator.getEntityAtKey(componentKey$); Core weblink=entity.getElementItem("web", weblinkKey$); */ // System.out.println("JBookmarkFacetOpenItem:open:selection="+selection$); JConsoleHandler.execute(console, weLocator$); } catch (Exception ee) { Logger.getLogger(JWebsetFacetOpenItem.class.getName()).info(ee.toString()); } } }); return popup; }
From source file:net.minelord.gui.panes.IRCPane.java
public void connected() { SwingUtilities.invokeLater(new Runnable() { @Override//from w w w .j a v a 2s. c o m public void run() { scroller.setBounds(scrollerWithoutTopicWithUserlist); scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); status = "Connected"; client.connectAlertListener(); TitledBorder title = BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Connected"); title.setTitleJustification(TitledBorder.RIGHT); userList = new JList(client.getUserList().toArray()); userScroller = new JScrollPane(userList); userScroller.setBounds(userScrollerWithoutTopic); userList.setBounds(0, 0, 210, 250); userList.setBackground(Color.gray); userList.setForeground(Color.gray.darker().darker().darker()); userScroller.setBorder(title); userScroller.getVerticalScrollBar().setUnitIncrement(5); scroller.setBorder(BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "")); if (client.getTopic().trim().length() > 0) { topic = new JLabel(client.getTopic()); scroller.setBounds(scrollerWithTopicWithUserlist); userScroller.setBounds(userScrollWithTopic); userList.setBounds(0, 0, 210, 225); title = BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Topic set by " + client.getTopicSetter()); title.setTitleJustification(TitledBorder.LEFT); topic.setBorder(title); topic.setBounds(topicBounds); add(topic); } else topic = new JLabel(""); input.setEnabled(true); input.requestFocus(); final JPopupMenu userPopup = new JPopupMenu(); JLabel breakLine = new JLabel("____"); JLabel help = new JLabel("Politely ask for help"); JLabel message = new JLabel("Message"); JLabel sortNormal = new JLabel("Normal"); JLabel sortAlphabetical = new JLabel("Alphabetical"); JLabel sortRoles = new JLabel("Roles"); help.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { userPopup.setVisible(false); sendMessage("/me kicks " + userList.getModel().getElementAt(userList.getSelectedIndex()) + " in the shins"); sendMessage("I need help you pleb"); } public void mouseReleased(MouseEvent e) { } }); message.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent paramMouseEvent) { userPopup.setVisible(false); input.setText("/msg " + userList.getModel().getElementAt(userList.getSelectedIndex()) + (input.getText().length() > 0 && input.getText().charAt(0) == ' ' ? input.getText() : " " + input.getText())); input.select(0, ("/msg " + userList.getModel().getElementAt(userList.getSelectedIndex()) + (input.getText().length() > 0 && input.getText().charAt(0) == ' ' ? "" : " ")) .length()); input.requestFocus(); } }); sortNormal.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent paramMouseEvent) { userPopup.setVisible(false); updateUserList(0); } }); sortAlphabetical.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent paramMouseEvent) { userPopup.setVisible(false); updateUserList(1); } }); sortRoles.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent paramMouseEvent) { userPopup.setVisible(false); updateUserList(2); } }); userPopup.add(help); userPopup.add(message); userPopup.add(breakLine); userPopup.add(sortNormal); userPopup.add(sortAlphabetical); userPopup.add(sortRoles); userList.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { check(e); } public void mouseReleased(MouseEvent e) { check(e); } public void check(MouseEvent e) { userList.setSelectedIndex(userList.locationToIndex(e.getPoint())); userPopup.show(userList, e.getX(), e.getY()); } }); add(userScroller); final JPopupMenu textPopup = new JPopupMenu(); JLabel copy = new JLabel("Copy"); copy.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent paramMouseEvent) { textPopup.setVisible(false); if (text.getSelectedText() != null && text.getSelectedText().length() != 0) { StringSelection selection = new StringSelection(text.getSelectedText()); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(selection, selection); } } }); textPopup.add(copy); text.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) textPopup.show(text, e.getX(), e.getY()); } }); add(userScroller); repaint(); } }); }