Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #29656
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2014-08-13 08:02 -0700 |
| References | <lsec34$d64$1@dont-email.me> <66hrbb-0uo.ln1@s.simpson148.btinternet.com> |
| Message-ID | <ca2557eb-e693-4b40-94e2-11c509ac636b@googlegroups.com> (permalink) |
| Subject | Re: Problem getting the JPopupMenu from the Action it generates |
| From | FredK <fred.l.kleinschmidt@gmail.com> |
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.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Problem getting the JPopupMenu from the Action it generates Knute Johnson <eternal@knutejohnson.com> - 2014-08-12 17:39 -0700
Re: Problem getting the JPopupMenu from the Action it generates Steven Simpson <ss@domain.invalid> - 2014-08-13 08:37 +0100
Re: Problem getting the JPopupMenu from the Action it generates FredK <fred.l.kleinschmidt@gmail.com> - 2014-08-13 08:02 -0700
Re: Problem getting the JPopupMenu from the Action it generates Knute Johnson <eternal@knutejohnson.com> - 2014-08-13 08:43 -0700
Re: Problem getting the JPopupMenu from the Action it generates Mike Amling <mamling@chaff.us> - 2014-08-14 00:12 -0500
Re: Problem getting the JPopupMenu from the Action it generates Steven Simpson <ss@domain.invalid> - 2014-08-14 09:54 +0100
Re: Problem getting the JPopupMenu from the Action it generates Knute Johnson <eternal@knutejohnson.com> - 2014-08-14 19:20 -0700
csiph-web