Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Popup menu

Status
Not open for further replies.

wangdong

Programmer
Oct 28, 2004
202
0
0
CN
I have two textPane on a JFrame and want to add a popup menu(copy/past) for each of them. How can I get around of creating two JPopupMenus? just use one for both?

Thank you!

Chinese Java Faq Forum
 
How can I resolve this:
Code:
jMenuItemCopy.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent e) {
                    Clipboard clipboard = getToolkit ().getSystemClipboard ();
                    StringSelection selection = new StringSelection(jTextPaneResultConsole.getSelectedText());
                    clipboard.setContents(selection,selection );                    
                }
            });
the jTextPaneResultConsole is a component need to give.

Chinese Java Faq Forum
 
Set up the component to source selected text from in a reference outside your anonymous ActionListener and set it to the correct one just before you pop up your menu. Use it inside the anonymous listener instead of the jTextPaneResultConsole instance.

(Sorry if that response is off track, but your last question was a little vague.)

Tim
 
That solution is ok for the copy action, but not for the past.

I can asign a value to a variable outside the listener, but when I do paste, how the program knows which component I am on.

Chinese Java Faq Forum
 
In a similar fashion. You need to set a reference to the component you are generating the pop up menu for. Then, in whatever listener is actioned in the pop up, it can reference this component, either to get the text, or to set it in a paste.

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top