Skip to main content

JPopupMenu and JEditorPane problem

1 reply [Last post]
mattg1981
Offline
Joined: 2006-02-17

Hi, I basically have a text editor program that uses a JEditorPane for the input portion of the app. I want to have a JPopupMenu so when the user right clicks on the JEditorPane, a menu will pop up with commands like cut, copy, past, etc. ... your normal right click commands.

My problem is I can get one or the other, but not both at the same time. I use:

textScrollPane.setViewportView(textBox);
getContentPane().add(textScrollPane);

(where textScrollPane is a JScrollPane and textBox is the JEditorPane).

I have tried textBox.add(new MouseMenu());

(where MouseMenu() is the JPopupMenu).

if I do:
getContentPane().add(textScrollPane);
getContentPane().add(new MouseMenu());

only the moues menu shows and I get a gray area where the JEditorPane should be.

Can someone help me so I can get both of the things at once.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Scott Violet

Matt,

A JPopupMenu isn't really meant to be added to another component,
instead you invoke 'show' when you want the JPopupMenu to be made
visible. Prior to 1.5 you will need to add the MouseListeners and
KeyListeners that detect when the popup should be shown and invoke
popupMenu.show appropriately, in 1.5 we added setComponentPopupMenu
that will take care of all this for you. Take a look at SwingSet2 for
examples.

-Scott

On Mon, Feb 16, 2004 at 12:20:15AM -0500, swing-feedback@javadesktop.org wrote:
> Hi, I basically have a text editor program that uses a JEditorPane for the input portion of the app. I want to have a JPopupMenu so when the user right clicks on the JEditorPane, a menu will pop up with commands like cut, copy, past, etc. ... your normal right click commands.
>
> My problem is I can get one or the other, but not both at the same time. I use:
>
> textScrollPane.setViewportView(textBox);
> getContentPane().add(textScrollPane);
>
> (where textScrollPane is a JScrollPane and textBox is the JEditorPane).
>
> I have tried textBox.add(new MouseMenu());
>
> (where MouseMenu() is the JPopupMenu).
>
> if I do:
> getContentPane().add(textScrollPane);
> getContentPane().add(new MouseMenu());
>
> only the moues menu shows and I get a gray area where the JEditorPane should be.
>
> Can someone help me so I can get both of the things at once.
> ---
> [Message sent by forum member 'mattg1981' (matt gimbl)]
>
> http://www.javadesktop.org/forums/thread.jspa?messageID=7026&#7026