This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Which Swing component to use ?

 
naveen yadav
Ranch Hand
Posts: 384
Java MyEclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ranchers ,

I am a creating a swing Gui interface in which a player has to select 6 numbers from the range of 1-50.

Which Swing component would be a good choice ?
 
Manuel Petermann
Ranch Hand
Posts: 177
Hibernate Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would use a jformattedtextfield combined with a jslider.
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to provide more information to get the best suggestion.

6 numbers together, or one by one?
6 numbers once, or repeatedly?

Prima facie, I would suggest 6 JComboBoxes with the drop-down set to display 10 rows, maybe 15 if placed near the top of a tall enough window to not look out of place. But a JSpinner for each number may be more appropriate, or maybe even six pairs of JSpinners, one for each digit of each number.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if this is for some type of lotto (pick 6), 50 x JToggleButton might be the go.

 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about a JList with a ListSelectionModel that only allows 0-6 selected items?
 
naveen yadav
Ranch Hand
Posts: 384
Java MyEclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:You need to provide more information to get the best suggestion.

.


i am working on a RMI based Lottery application in which a player, on client side, have to select 6 numbers from the range of 1-50.Once all 6 numbers are selected
these number send to server and those all 6 numbers are matched against a random number generated by the server.

 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then Michael's suggestion looks to be the best approach.

edit You might want to add logic that disables unselected buttons when 6 are already selected.
 
naveen yadav
Ranch Hand
Posts: 384
Java MyEclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am trying the 6 JSpinner but facing a problem .

the problem is when i changes the input field of one JSpinner , the value of input field of all other 5 JSpinner also changes simultaneously .

here is a code



what is the problem here ?
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They all have the same model.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you want to select 6 from 50, but using JSpinners all you're doing is
picking 1 from 50 and doing it 6 times. As is, the same number can
be selected 6 times.

some people even pick patterns, not numbers, so JSpinner really is a poor choice.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic