javax.swing.JPopupMenu cannot be cast to javax.swing.JMenuItem



Hello All,

To get the text of runtime built menu items, I used the following
code:
-------------------------------------------------------------------------------------------------------

//Create a change listener and register with the menu selection
manager
MenuSelectionManager.defaultManager().addChangeListener(
new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
// Get the selected menu or menu item
MenuSelectionManager msm =
(MenuSelectionManager)evt.getSource();
MenuElement[] path = msm.getSelectedPath();
if (path != null && path.length > 0){
------------> String m_sSelectedMenuItem =
((JMenuItem)(path[path.length - 1])).getText();
}
}
}
);
-------------------------------------------------------------------------------------------------------
However, I recieve the following exception
java.lang.ClassCastException: javax.swing.JPopupMenu cannot be
cast to javax.swing.JMenuItem
on the stared pointed line above.
This is obviously also hardens my debugging work as the exception
always being thrown when I select the menu item...

Any ideas?
Many thanks!

.



Relevant Pages

  • RE: Ok to call Application.get_Selection()?
    ... We get an exception that says COMException ... Cannot create a Selection object when this dialog is active. ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.office.developer.com.add_ins)
  • origin of error message
    ... i was trying to create an image using user selection of a file in tix ... Exception exceptions.AttributeError: "PhotoImage instance has no ...
    (comp.lang.python)
  • Re: Getting selected TextRange
    ... whether the current selection is Slides, Shapes, Text or nothing. ... BoundLeft and .BoundWidth will increase by equal amounts. ... Because sel.TextRange throws an exception when getting some properties ... Cubicle Wars - http://www.windwardreports.com/film.htm ...
    (microsoft.public.powerpoint)
  • Re: Selecting Listview Rows
    ... > My first selection runs fine, but my second selection throws a native ... > But if I try to repeat the process, I get the exception on the ... > Quit terminates ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Problem with CommandBarComboBox Change Event (Event fires only once)
    ... garbage collector. ... Set a module or global reference to things so they aren't ... body whenever user changes selection in the Combo Box. ... There comes no exception and it works fine for first selection. ...
    (microsoft.public.outlook.interop)