This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes addBindings only be effective once, then no response with another click. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "addBindings only be effective once, then no response with another click." Watch "addBindings only be effective once, then no response with another click." New topic
Author

addBindings only be effective once, then no response with another click.

Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
I called the following code in the constructor, it worked, but once the Ctrl-V is hitted, data is copied, another Ctrl-V keystroke causes nothing to happen.
Why is that?
Here is the code.

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
you're using the getInputMap() that requires the component to have focus,
and if updateAgeField() gives the focus to some other component, it won't
work the 2nd time.

but that's just a guess - we can't run the code to test it.
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
Michael Dunn wrote:you're using the getInputMap() that requires the component to have focus,
and if updateAgeField() gives the focus to some other component, it won't
work the 2nd time.

but that's just a guess - we can't run the code to test it.



Hmmm, this guess is a bit off. I commented out that line, still it doesn't allow me to cut-n-paste twice

Thanks
Jack
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
I started to inspect this event handler

The cut-n-paste stuff only stopped working when I clicked on this button. But I would like to allow the user to clear all the fields on the form.
So this button is inevitable to be clicked. Any ideas how to change my program?
Thanks
Jack
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
read my reply again, and use the correct input map
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
Michael Dunn wrote:read my reply again, and use the correct input map


Thanks Michael
This time, the actionPerformed method is never called.
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
Anyone would like to offer some help. That'll be nice of you.

Thanks
Jack
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2332
    
  50
Without seeing how these components are laid out it's hard to give precise advice but Michael's comments seem correct to me.
I don't know what JSplitPane1 is but I'm guessing from the name it's a split panel in which case it won't get focus so you should probably use jSplitPane1.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT...
Note though that this will also stop working if you have other visible panels that aren't children of this panel and the focus moves to a component in one of those other panels.
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
Tony Docherty wrote:Without seeing how these components are laid out it's hard to give precise advice but Michael's comments seem correct to me.
I don't know what JSplitPane1 is but I'm guessing from the name it's a split panel in which case it won't get focus so you should probably use jSplitPane1.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT...
Note though that this will also stop working if you have other visible panels that aren't children of this panel and the focus moves to a component in one of those other panels.


One thing remarkable is that when I excluded the parameter of getInputMap, the cut-n-paste action worked just fine. When I included anyone of them. It stopped working.
The JFrame is divided by this split Pane, with a Panel over the top and a scroll panel at the bottom(in the middle), then there is another Panel over the bottom (inside the split panel), which is a JTabbedPane
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2332
    
  50
One thing remarkable is that when I excluded the parameter of getInputMap, the cut-n-paste action worked just fine.

Not so remarkable: cut, copy and paste support is built into the swing text components - see this tutorial http://docs.oracle.com/javase/tutorial/uiswing/dnd/cutpaste.html

I assumed you wanted to take over the default CCP handling to do something esoteric, if that is the case please provide an SSCCE and a full description of what you are trying to achieve.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
the problem appears to be if any textComponent has the focus, Ctrl-V is processed/consumed by the component before the bindings trigger.
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
Michael Dunn wrote:the problem appears to be if any textComponent has the focus, Ctrl-V is processed/consumed by the component before the bindings trigger.


Michael's guess is correct. It seems to be working now.
Thanks
Jack
 
jQuery in Action, 2nd edition
 
subject: addBindings only be effective once, then no response with another click.