GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes Which Swing component to use ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Which Swing component to use ?" Watch "Which Swing component to use ?" New topic
Author

Which Swing component to use ?

naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

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

Joined: Jul 19, 2011
Posts: 175

I would use a jformattedtextfield combined with a jslider.


Please correct my English.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4572
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
if this is for some type of lotto (pick 6), 50 x JToggleButton might be the go.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

How about a JList with a ListSelectionModel that only allows 0-6 selected items?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

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

Joined: May 03, 2008
Posts: 4572
    
    5

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

Joined: Oct 23, 2011
Posts: 384

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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

They all have the same model.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
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.
 
GeeCON Prague 2014
 
subject: Which Swing component to use ?