X-Received: by 10.236.83.171 with SMTP id q31mr2068716yhe.13.1407942122025; Wed, 13 Aug 2014 08:02:02 -0700 (PDT) X-Received: by 10.51.17.69 with SMTP id gc5mr164975igd.0.1407942121929; Wed, 13 Aug 2014 08:02:01 -0700 (PDT) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!j15no6830811qaq.0!news-out.google.com!px9ni588igc.0!nntp.google.com!h18no19580669igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.programmer Date: Wed, 13 Aug 2014 08:02:01 -0700 (PDT) In-Reply-To: <66hrbb-0uo.ln1@s.simpson148.btinternet.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=130.76.32.209; posting-account=_7xgmwoAAADi7iXKBO-oX5zbCfSzsCV0 NNTP-Posting-Host: 130.76.32.209 References: <66hrbb-0uo.ln1@s.simpson148.btinternet.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Problem getting the JPopupMenu from the Action it generates From: FredK Injection-Date: Wed, 13 Aug 2014 15:02:01 +0000 Content-Type: text/plain; charset=ISO-8859-1 X-Received-Bytes: 2237 X-Received-Body-CRC: 2848837921 Xref: csiph.com comp.lang.java.programmer:29656 On Wednesday, August 13, 2014 12:37:10 AM UTC-7, Steven Simpson wrote: > 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? > > Better yet, pass the target component (in your case, tf) as an argument to the someAction constructor. -- Fred K.