Re: JMenu holding JButton instances - bug with 5.0?
- From: allen@xxxxxxxxxxxxxxxxx
- Date: 29 Apr 2005 00:01:32 -0700
Hi,
Thank you very much - this is really interesting! I resorted to using
JMenuItems for the JButtons, with a bit of tweaking they can look
better. However this discussion makes me amazed that some of my other
code ever worked to start off with. I've embedded a JTable (in a
scrollpane) using JCheckBox cell-renderers/editors into a JPopupMenu,
and based on your description here, I'm amazed that it worked. It is
sad that there is this potential problem however, since I find that
being able to embed configuration items into a popup menu reduces the
number of levels of configuration dialogs that I would otherwise have
to resort to in order to present all the configuration details to the
user.
Thanks for your time and advice.
Allen
John McGrath wrote:
> I just traced through this, and I think my first impressions were
correct.
> It is a royal mess! Here is what I found:
>
> The mousePressed and mouseClicked events get through to the JButton,
but
> the mouseReleased event does not seem to. As a result, the JButton
does
> not fire an ActionEvent.
>
> The MenuSelectionManager retargets the mouseReleased event, consuming
the
> original event and creating a new event that it sends to the
JPopupMenu.
> However, the JPopupMenu ignores this event.
>
> Since the original event is consumed, you would think it should be
> ignored, and under most circumstances, it is. However, for some
reason it
> only checks if the event has been consumed after it has allowed
> InputMethods to process it. Obviously, it needs to check to see if
an
> InputMethod has consumed the event, but I do not see why it does not
do so
> under other circumstances.
>
> So what is happening to your mouseReleased event is that it is being
> marked as consumed by the MenuSelectionManager, and then the event
> processing is stopped after InputMethod processing. If you disable
> InputMethods on the buttons (which really does not makes sense
anyway), it
> continues to process the event, even though it has been consumed().
>
> So if you set enableInputMethods(false) on the buttons (checkboxes,
radio
> buttons, etc) that you place on the menu, the buttons will work. I
really
> think it would be a bad idea to depend on this, since it will likely
break
> in a subsequent Java version, but if you need something that works
*now*,
> this may be the answer. I would definitely recommend that you get
rid of
> the use of non-MenuItem components in your menus.
>
> --
> Regards,
>
> John McGrath
.
- Follow-Ups:
- Re: JMenu holding JButton instances - bug with 5.0?
- From: John McGrath
- Re: JMenu holding JButton instances - bug with 5.0?
- References:
- JMenu holding JButton instances - bug with 5.0?
- From: allen
- Re: JMenu holding JButton instances - bug with 5.0?
- From: John McGrath
- JMenu holding JButton instances - bug with 5.0?
- Prev by Date: Re: Replace row in JTable
- Next by Date: Re: Difference between itemStateChanged and stateChanged for a JCheckBoxMenuItem
- Previous by thread: Re: JMenu holding JButton instances - bug with 5.0?
- Next by thread: Re: JMenu holding JButton instances - bug with 5.0?
- Index(es):