File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jacky Luk
Ranch Hand
Posts: 634
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 634
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 634
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
read my reply again, and use the correct input map
 
Jacky Luk
Ranch Hand
Posts: 634
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 634
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone would like to offer some help. That'll be nice of you.

Thanks
Jack
 
Tony Docherty
Bartender
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 634
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 634
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic