Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #1482
| From | "dushkin" <dushkin@THRWHITE.remove-dii-this> |
|---|---|
| Subject | javax.swing.JPopupMenu ca |
| Message-ID | <1176904573.130795.138220@y80g2000hsf.googlegroups.com> (permalink) |
| Newsgroups | comp.lang.java.gui |
| Date | 2011-04-27 15:33 +0000 |
| Organization | TDS.net |
To: comp.lang.java.gui
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!
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
Back to comp.lang.java.gui | Previous | Next — Next in thread | Find similar | Unroll thread
javax.swing.JPopupMenu ca "dushkin" <dushkin@THRWHITE.remove-dii-this> - 2011-04-27 15:33 +0000 Re: javax.swing.JPopupMen "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:33 +0000 Re: javax.swing.JPopupMen "dushkin" <dushkin@THRWHITE.remove-dii-this> - 2011-04-27 15:33 +0000 Re: javax.swing.JPopupMen "dushkin" <dushkin@THRWHITE.remove-dii-this> - 2011-04-27 15:33 +0000
csiph-web