• Post Reply Bookmark Topic Watch Topic
  • New Topic

Two strange behaviour in Swing

 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,
Today i noticed two strange behaviour in swing.
Case 1: Normally for every key events we used to get one keyPress and one keyRelease events.But this is not of the case with PrintScreen key. I tested this behaviour on the JNLP file used in java tutorial at this link itself.

Question: Why only PrintScreen has this kind of event associated with it?

Case 2: One more thing is that whenever we create a JMenu component on the JFrame we are able to access this menu by Left-Clicking on the JMenu component but accidentally i made a right click on the JMenu and that too populates the JMenu.

Question: How can i restrict Right-Clicking on the JMenu Component?
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried the first as well, but my PrtScr button triggered exactly one pressed and one released event each time I pressed it. Perhaps it is caused by your keyboard driver - do you get the same results on a different Pc?
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya i am getting only keyReleased event on my PC.
This one was reported as a bug by our client.So i tried for a hour after that only i figured out that PrintScreen key generates only keyReleased event so i gave it a try on another PC which also generates same keyReleased event

I am not sure whether my keyboard driver is causing problem.But i don't installed any driver specially for my keyboard i have the standard driver installed from my OS itself (Win2000).

Added images for your reference
1.JNLP file under my PC


2.My Keyboard Driver

[ May 21, 2008: Message edited by: Balasubramanian Chandrasekaran ]
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to see the behaviour under Linux.
But the PrntScrn key was caught by OS itself and it is not letting the keyevent go through Java.

I tried opening the same JNLP file under my linux machine which is Fedora Core 8 and i am not able to see the behaviour under linux system.But still the issue is occuring in all Win2000 systems.
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like no one knows how to handle first case.

Did anyone show some light on the second case which i asked?

Please note that i am not talking about JPopupMenu in my second case.

Waiting for reply.....
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As for the first case, it looks like this is handled in the keyboard driver of the operating system - there's nothing you can really do from Java if the operating system is grabbing the key event first.

For the second, I made a UI delegate that ignores any mouse button except for the main button.



You can set it on each JMenu by calling setUI() on each JMenu you have... I have attempted to set it for *all* JMenus in a program by calling UIManager.put("MenuUI", OverrideMouseMenuUI.class.getName()), which should work, but for some reason it isn't... not sure if it's a JDK issue, classloading issue, or what.

(By the way, the behavior of reacting to any mouse click is inherited from the JMenuItem... you can right click on a menu to open it, and also right click on a menu item to launch it. )
[ May 23, 2008: Message edited by: Nathan Pruett ]
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nathan Pruett:
For the second, I made a UI delegate that ignores any mouse button except for the main button.
.....
(By the way, the behavior of reacting to any mouse click is inherited from the JMenuItem... you can right click on a menu to open it, and also right click on a menu item to launch it. )

[ May 23, 2008: Message edited by: Nathan Pruett ]


So there is nothing we can do to restrict the behavior.
Thanks for the reply nathan pruett
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't say nothing, but it's probably harder than you're willing to go. Like rewriting part of the component, like its UI. Perhaps even more.
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:
I wouldn't say nothing, but it's probably harder than you're willing to go. Like rewriting part of the component, like its UI. Perhaps even more.


ok i can leave that part as i don't have that much time to research its UI.Anyway,thanks for the reply and i hope it will be continued
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!