javax.swing.JPopupMenu cannot be cast to javax.swing.JMenuItem
- From: dushkin <dushkin@xxxxxxxxxx>
- Date: 18 Apr 2007 06:56:13 -0700
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!
.
- Prev by Date: Re: GridBagLayout not behaving as specified
- Next by Date: Re: GridBagLayout not behaving as specified
- Previous by thread: GridBagLayout not behaving as specified
- Next by thread: Re: javax.swing.JPopupMenu cannot be cast to javax.swing.JMenuItem
- Index(es):
Relevant Pages
|