• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextField with arrow listener(up&down).

 
Rush Art
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
JTextFieldButtons.JPG
[Thumbnail for JTextFieldButtons.JPG]
Example
 
Campbell Ritchie
Sheriff
Pie
Posts: 49372
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Swing forum
 
Rob Spoor
Sheriff
Pie
Posts: 20546
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Maneesh Godbole
Saloon Keeper
Posts: 11065
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
 
Rush Art
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Example.JPG
[Thumbnail for Example.JPG]
Example.
 
Rob Spoor
Sheriff
Pie
Posts: 20546
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic