Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #1482 > unrolled thread
| Started by | "dushkin" <dushkin@THRWHITE.remove-dii-this> |
|---|---|
| First post | 2011-04-27 15:33 +0000 |
| Last post | 2011-04-27 15:33 +0000 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.java.gui
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
| From | "dushkin" <dushkin@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:33 +0000 |
| Subject | javax.swing.JPopupMenu ca |
| Message-ID | <1176904573.130795.138220@y80g2000hsf.googlegroups.com> |
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
[toc] | [next] | [standalone]
| From | "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:33 +0000 |
| Subject | Re: javax.swing.JPopupMen |
| Message-ID | <70e3d1a86d514@uwe> |
| In reply to | #1482 |
To: comp.lang.java.gui
dushkin wrote:
.
> 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
--
Andrew Thompson
http://www.athompson.info/andrew/
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-gui/200704/1
---
* 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
[toc] | [prev] | [next] | [standalone]
| From | "dushkin" <dushkin@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:33 +0000 |
| Subject | Re: javax.swing.JPopupMen |
| Message-ID | <1176908972.010957.30390@y80g2000hsf.googlegroups.com> |
| In reply to | #1482 |
To: comp.lang.java.gui 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... --- * 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
[toc] | [prev] | [next] | [standalone]
| From | "dushkin" <dushkin@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:33 +0000 |
| Subject | Re: javax.swing.JPopupMen |
| Message-ID | <1176912257.646063.231780@p77g2000hsh.googlegroups.com> |
| In reply to | #1482 |
To: comp.lang.java.gui 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! --- * 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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.gui
csiph-web