Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Steven Simpson Newsgroups: comp.lang.java.programmer Subject: Re: Problem getting the JPopupMenu from the Action it generates Date: Wed, 13 Aug 2014 08:37:10 +0100 Organization: A noiseless patient Spider Lines: 21 Message-ID: <66hrbb-0uo.ln1@s.simpson148.btinternet.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: mx05.eternal-september.org; posting-host="4ff3a9d2065b2eeed064d158c86dc57f"; logging-data="15173"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+TnoyfwlY8V/8iFGwqN5QKYwqKfkSbOH8=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 In-Reply-To: Cancel-Lock: sha1:aGLOD4jboIMx4/f7ikIsGMeYKuU= Xref: csiph.com comp.lang.java.programmer:29654 On 13/08/14 01:39, Knute Johnson wrote: > I'm having a problem getting the JPopupMenu from an Action that is > generated by the JPopupMenu. The error is a ClassCastException and it > is saying that what is returned by ActionEvent.getSource() cannot be > cast to a JPopupMenu because it is a JPopupMenu$1. JPopupMenu$1 is an > anonymous class and shouldn't be returned by ActionEvent.getSource(). Why not? The JPopupMenu.add(Action) method creates a JMenuItem (of type JPopupMenu$1), adds it to the menu, and returns it. If you click that item, it will be the source. > In the end, I'm trying to get to the component that was right clicked > to pop up the menu. Couldn't see anything, but why not pass popupMenu as a constructor argument to someAction? -- ss at comp dot lancs dot ac dot uk