addBindings only be effective once, then no response with another click.
Jacky Luk
Ranch Hand
Joined: Aug 02, 2012
Posts: 198
posted
0
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
posted
0
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: 198
posted
0
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: 198
posted
0
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
posted
0
read my reply again, and use the correct input map
Jacky Luk
Ranch Hand
Joined: Aug 02, 2012
Posts: 198
posted
0
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: 198
posted
0
Anyone would like to offer some help. That'll be nice of you.
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: 198
posted
0
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
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
posted
0
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: 198
posted
0
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