aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTextField with arrow listener(up&down). Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextField with arrow listener(up&down)." Watch "JTextField with arrow listener(up&down)." New topic
Author

JTextField with arrow listener(up&down).

Rush Art
Greenhorn

Joined: Oct 17, 2009
Posts: 7
Hello, I am having hard to finding a code to manage to get this arrow listener(up&down) for a JTextField. I've taken a picture to show what I mean(Attachment).

Thanks.



[Thumbnail for JTextFieldButtons.JPG]

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
Moving to Swing forum
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19695
    
  20

Check out JSpinner. for the first one you will need a SpinnerListModel, for the second one a SpinnerNumberModel. Also check out spinner editors. In short, you can create these two fields like this:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10376
    
    8

More information on spinners here
http://java.sun.com/docs/books/tutorial/uiswing/components/spinner.html


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Rush Art
Greenhorn

Joined: Oct 17, 2009
Posts: 7
Hello, I took a look at your example. I am still having hard to fitting the JSpinner into this part of the code. What am I missing? The shown example is how the complete look should look like, every part is done except the JSpinner.

Thanks.




[Thumbnail for Example.JPG]

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19695
    
  20

1) Your country spinner will not contain the contents of the country array. You need to use this array inside your SpinnerListModel for the country spinner.

2) The years are hard coded this way but again not used. The SpinnerNumberModel has been defined without any parameters so that means its minimum value is Integer.MIN_VALUE, its maximum value is Integer.MAX_VALUE and its current value is 0. Try this:
This will also use the years from 1998 until 2003 with 1998 as the default.

3) You have nowhere added these two spinners to your user interface.


Now before asking any more questions I suggest you really read that link Maneesh has given you. It will probably help you understand how spinners work instead of just copying some example.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTextField with arrow listener(up&down).