Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #4190
| From | "wx" <wx@THRWHITE.remove-dii-this> |
|---|---|
| Subject | Re: Detect when menu is c |
| Message-ID | <7010b8f0-dc1c-4784-a513-cc4e7a9ac4c5@59g2000hsb.googlegroups.com> (permalink) |
| Newsgroups | comp.lang.java.gui |
| References | <ga91u3$v9l$1@registered.motzarella.org> |
| Date | 2011-04-27 15:49 +0000 |
| Organization | TDS.net |
To: comp.lang.java.gui
> Reading it up once again I see I've got it wrong. Now I see you
want a single action listener for all menu items and you want it
called back for any new items there may be added to the container,
right? I'm sorry to say I haven't thought about that.
<
I don't know whether I understand this, but let me try to rephrase my
question. Assume you have the menu:
A
+- B
| +- C
| +- D
|
+- E
+- F
+- G
Now, assume you click on A. It would open this:
A
+- B >
+- E >
This is because A is e.g. JMenuBar that is activated by a click, not
by mouse roll over. Now, if you only roll over B and wait, but not
click, you will get the following:
A
+- B
| +- C
| +- D
|
+- E >
This is what is called selection. I can get notifications about this
by adding the following:
menu2.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
System.out.println("menu2: itemStateChanged: " +
e.getStateChange());
}
});
before the for loop in my code sample. This is not what I want.
Assume now, in this state, you actually move your mouse over C and
actually click on C (which is a JMenuItem). It will raise an action
event on the respective MenuItem instance. You also get this if you
type Enter while item C is selected. That is a normal behavior. What
is important is that method is not relevant - whether I click with the
mouse or press Enter key on my keyboard or I have an application
programmatically generate this event - is irrelevant and that is a
good abstraction. I get actionPerformed, which means the item has been
chosen.
Now, assume you move your mouse over B and actually click on B (which
is a JMenu). What I would like is that the action listener I
registered this receives this. The only thing I get is mouse clicked
event, as demonstrated by the example. I cannot get keyboard events,
nor can I get action events. This is logically incorrect from my
perspective:
- JMenu is a descendant of AbstractButton - you, by every logic,
should be able to click on buttons and react, shouldn't you?
- You can receive mouse, but not keyboard events
- You cannot determine that JMenu has been chosen, you can only
determine whether it was (de)selected
Hope this explains the problem and the solution I am searching for in
a better way.
---
* 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 — Previous in thread | Next in thread | Find similar
Detect when menu is chose "wx" <wx@THRWHITE.remove-dii-this> - 2011-04-27 15:49 +0000
Re: Detect when menu is c "Stanimir Stamenkov" <stanimir.stamenkov@THRWHITE.remove-dii-this> - 2011-04-27 15:49 +0000
Re: Detect when menu is c "wx" <wx@THRWHITE.remove-dii-this> - 2011-04-27 15:49 +0000
Re: Detect when menu is c "Stanimir Stamenkov" <stanimir.stamenkov@THRWHITE.remove-dii-this> - 2011-04-27 15:49 +0000
Re: Detect when menu is c "Stanimir Stamenkov" <stanimir.stamenkov@THRWHITE.remove-dii-this> - 2011-04-27 15:49 +0000
Re: Detect when menu is c "wx" <wx@THRWHITE.remove-dii-this> - 2011-04-27 15:49 +0000
Re: Detect when menu is c "Stanimir Stamenkov" <stanimir.stamenkov@THRWHITE.remove-dii-this> - 2011-04-27 15:49 +0000
Re: Detect when menu is c "wx" <wx@THRWHITE.remove-dii-this> - 2011-04-27 15:49 +0000
Re: Detect when menu is c "Stanimir Stamenkov" <stanimir.stamenkov@THRWHITE.remove-dii-this> - 2011-04-27 15:49 +0000
csiph-web