participate


Swing - A copy of a jspinner shows the same value as the original...
This question is not answered.

<<   Back to Forum  |   Give us Feedback
This topic has 13 replies on 1 page.
cstrieder
Posts:20
Registered: 8/4/09
A copy of a jspinner shows the same value as the original...   
Nov 3, 2009 8:19 AM
 
 
Hi,

I need a Panel with 32 jspinner,..., so I made the first one and then make copies for the other 31.

The problem is that when in use, change in the value of one of them cause all the others to show the same value...

It seems there is some kind of link between the copies...

Some one have idea of what can be causing this behavior?

Edited by: cstrieder on Nov 3, 2009 4:18 PM

Edited by: cstrieder on Nov 3, 2009 4:19 PM
 
georgemc
Posts:16,804
Registered: 5/8/06
Re: A copy of a jspinner shows the same value as the original...   
Nov 3, 2009 8:21 AM (reply 1 of 13)  (In reply to original post )
 
 
And how did you make these "copies", exactly?
 
camickr
Posts:32,733
Registered: 2/27/98
Re: A copy of a jspinner shows the same value as the original...   
Nov 3, 2009 8:22 AM (reply 2 of 13)  (In reply to original post )
 
 
In the future, Swing related questions should be posted in the Swing forum.

Well, I have no idea how you are copying the spinners so the only advice I can give is, don't share the same SpinnerModel.

If you need further help then you need to create a Short, Self Contained, Compilable and Executable, Example Program (SSCCE), that demonstrates the incorrect behaviour.

Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.
 
MarksmanKen
Posts:126
Registered: 8/28/07
Re: A copy of a jspinner shows the same value as the original...   
Nov 3, 2009 8:26 AM (reply 3 of 13)  (In reply to original post )
 
 
I will bet any money that its because you've created 2 spinners but using only one model right?
You need to create a seperate model for each JSpinner you want to make individual.

Ken
 
cstrieder
Posts:20
Registered: 8/4/09
Re: A copy of a jspinner shows the same value as the original...   
Nov 3, 2009 8:36 AM (reply 4 of 13)  (In reply to #1 )
 
 
Ctrl+C, Ctrl+V
 
cstrieder
Posts:20
Registered: 8/4/09
Re: A copy of a jspinner shows the same value as the original...   
Nov 3, 2009 8:41 AM (reply 5 of 13)  (In reply to #2 )
 
 
I am sharing the SpinnerModel.

So I need to create 32 SpinnerModel?
 
camickr
Posts:32,733
Registered: 2/27/98
Re: A copy of a jspinner shows the same value as the original...   
Nov 3, 2009 8:45 AM (reply 6 of 13)  (In reply to #5 )
 
 
I am sharing the SpinnerModel. So I need to create 32 SpinnerModel?

What part of "don't share the spinner model" is not clear?
 
MarksmanKen
Posts:126
Registered: 8/28/07
Re: A copy of a jspinner shows the same value as the original...   
Nov 3, 2009 8:47 AM (reply 7 of 13)  (In reply to #4 )
 
 
cstrieder wrote:
Ctrl+C, Ctrl+V

Oh dear I dont think thats what he ment by how did you copy them....lol

If you have created 2 Jspinners with the new keyword you also need to create 2 Spinner Models as mentioned above and psss them into the constructors of the spinners:

String [] stuff = {"Blah", "Blah2", "Blah3"};
SpinnerListModel spinnerModel1 = new SpinnerListModel(stuff);   //Theres different types
SpinnerListModel spinnerModel2 = new SpinnerListModel(stuff);
JSpinner spinner1 = new JSpinner(spinnerModel1);
JSpinner spinner2 = new JSpinner(spinnerModel2);


Its not correct but it gives you an idea on how it should be done.

Ken
 
georgemc
Posts:16,804
Registered: 5/8/06
Re: A copy of a jspinner shows the same value as the original...   
Nov 3, 2009 8:46 AM (reply 8 of 13)  (In reply to #4 )
 
 
cstrieder wrote:
Ctrl+C, Ctrl+V

:headdesk:

I'm not feeling patient enough to work with this today.
 
georgemc
Posts:16,804
Registered: 5/8/06
Re: A copy of a jspinner shows the same value as the original...   
Nov 3, 2009 8:51 AM (reply 9 of 13)  (In reply to #6 )
 
 
camickr wrote:
I am sharing the SpinnerModel. So I need to create 32 SpinnerModel?

What part of "don't share the spinner model" is not clear?

I'm going to go out on a limb, based on previous experience, and say "the part that isn't Java source code".
 
DarrylBurke
Posts:15,598
Registered: 7/2/07
This Thread is now moved   
Nov 3, 2009 8:59 AM (reply 10 of 13)  (In reply to #9 )
 
 
Note: This thread was originally posted in the Java Programming forum, but moved to this forum for closer topic alignment.
 
cstrieder
Posts:20
Registered: 8/4/09
Re: A copy of a jspinner shows the same value as the original...   
Nov 4, 2009 2:47 AM (reply 11 of 13)  (In reply to #7 )
 
 
Sorry about my answer "Ctrl+C/Ctrl+V". In fact I did not understood what I can answer for that question..But the comments were funny...

The point is, I have two models for every spinner, one or other model is selected by a radio button for every jspinner. And I have 32 jspinner components - this gives me 64 models.

I need to code 64 defferent models in this case?
 
WalterLaan
Posts:816
Registered: 4/17/08
Re: A copy of a jspinner shows the same value as the original...   
Nov 4, 2009 7:51 AM (reply 12 of 13)  (In reply to #11 )
 
 
Typically you would code a method (eg createSpinnerWithTwoModels) which you call 32 times in a loop.

But perhaps calling it 33 times so you have a spare if one breaks down would be prudent.
 
camickr
Posts:32,733
Registered: 2/27/98
Re: A copy of a jspinner shows the same value as the original...   
Nov 4, 2009 7:56 AM (reply 13 of 13)  (In reply to #11 )
 
 
I need to code 64 defferent models in this case?

Quit wasting our time!

Did you try it? What happened?

Where is your SSCCE?
 
This topic has 13 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics

About Sun forums
  • Sun Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Sun Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums