last day (15 days later) » 

11:49 PM
2
A: Increase step size on JSpinner when a certain key is pressed

Hovercraft Full Of EelsAgain, I'd use Key Bindings to solve this, and I'd use bindings bound to the JSpinner's InputMap that's active when it has focus: InputMap inputMap = spinner.getInputMap(JComponent.WHEN_FOCUSED); A working small example program could look like this: import java.awt.event.ActionEvent; import...

 
+1 for a good answer. It's a bit more complicated than i thought it would be but i see how it works. Thanks, another day learning something :)
 
@Chax: Key Bindings are a bit more complicated than KeyListeners, but for this situation they work a whole lot better, and like most things, once you get used to them, coding them becomes second nature.
@Chax: also please look at the structure of my answer -- a minimal program that illustrates the problem and a solution. For future similar questions, consider posting a similar type of program, a minimal example program, one that we can compile and run and one that demonstrates the problem directly for us. This will make helping you much easier.
 
I thought that my question was simple enought not to have to make a small program. I'll try to remember that and post a minimal program example next time. Also is it possible to add another keyBinding for even bigger step? or would i need another AbstractAction class?
 
@Chax: but to solve it, I had to create one of these programs, which means extra effort on my part when it's your question. Your effort should be in making it as easy as possible for others to answer, so this should be done by you. You can add as many Key Bindings as you'd like or need.
 
Thanks again. Next time i'll post a question i'll put a Minimal example program for you to help me on ;)
@ Hovercraft Full Of Eels Can i ask you one more question? It's from your example.
 
11:49 PM
@Chax: ask away
 
Why do you have to put a string in this line : actionMap.put(**DOUBLE_STEP** + onKeyRelease, new DoubleStepAction(onKeyRelease));. I have read multiple post and I don't get it.
 
@Chax: I don't think that it has to be a String. It has to be some object whose equals and hashCode methods have been overridden so that you can use it as a hash key to allow the InputMap element to be matched to a corresponding ActionMap element.
 
So each keyBinding has to have a different hash key? If by example i wanted to put two keyBind on the same Component i have to put different hash key.
 
@Chax: to be honest, I've not looked at the source code for Key Bindings and don't know if a HashMap is used, and I've always used Strings as my keys (and suggest that you do the same). But for each binding, yes, you should use a unique key. My code above uses two unique keys, since the boolean variable onKeyRelease changes from false to true between creation of the two bindings.
Hello?
 
I still got question. Do you have a bit of time to help me out?
 
11:49 PM
A little bit. It is Saturday night though.
 
I tried to adapt your code to mine and it's not working
 
I changed teh key to VK_DOWN
Your code works well and in mine the JSpinner just decrement
Any idea
 
Oh, don't use VK_DOWN since your JSpinner uses that key itself to scroll its value down. Use pretty much any key but DOWN and UP.
 
I tried with VK_D and it just write ddddddddd in the TextArea
I wanted to use VK_CONTROL but it's not even changing the stepsize
 
11:52 PM
Then the JTextArea has the focus at the time that you are attempting this.
 
Do when i click on a button on the JSpinner the textarea automatically get the focus?
 
You should create and post a new question, one with your minimal example program, one where you describe in greater detail just what you're trying to accomplish, and where you describe how your code isn't working.
 
Ok will do. Thanks again for your time. I really appreciate
 

last day (15 days later) »