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!
Andrew Thompson - 18 Apr 2007 15:07 GMT
..
> java.lang.ClassCastException: javax.swing.JPopupMenu cannot be
>cast to javax.swing.JMenuItem
..
>Any ideas?
1) instanceof
2)
try {
..one
catch(CCE) {
try {
..the other
catch(CCE) {
..debug the code
}
}
3) redesign it

Signature
Andrew Thompson
http://www.athompson.info/andrew/
dushkin - 18 Apr 2007 16:09 GMT
First andrew thanks for the reply.
Second, It may be the late afternoon which causes me a little to
misunderstand your suggestions... I'll be glad to get more detailed
help. I really didn't understand the solution...
dushkin - 18 Apr 2007 17:04 GMT
dushkin כתב:
> First andrew thanks for the reply.
> Second, It may be the late afternoon which causes me a little to
> misunderstand your suggestions... I'll be glad to get more detailed
> help. I really didn't understand the solution...
Ok, I got it with the instanceof....
Thanks again!