Results 1 to 17 of 17
Thread: Got some trouble with JComboBox
- 09-05-2008, 07:36 AM #1
Member
- Join Date
- Aug 2008
- Posts
- 41
- Rep Power
- 0
Got some trouble with JComboBox
I have some code like this:
int i ;
for( i = 0 ; i < jComboBox1.getItemCount(); i++)
{
if(jComboBox1.getSelectedIndex() == i)
{
jComboBox2.addItem(jComboBox1.getSelectedItem());
}
}
int index = jComboBox1.getSelectedIndex();
jComboBox1.removeItemAt(index);
I have 2 comboBox , first have 3 items , second have nothing.
I want : when we choose any item of First ComboBox, it will auto add to Second ComboBox,and then, the item we choose in First Box will auto remove.
And i got some trouble:
.First is : when the item from First Box auto add to Second Box, it auto add 2 same item .
.Second is : when i try to remove the item that we choose, it will remove all item from the item we choose to the last item.
Can you guys help me? Or tell me what i'm wrong! Thanks!!
- 09-05-2008, 08:15 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Better to use action listeners for this. Did you try something related?
- 09-05-2008, 08:47 AM #3
Member
- Join Date
- Aug 2008
- Posts
- 41
- Rep Power
- 0
Oh, i use ItemStateChange for this.
I 'll try Action Listener.
Thanks Mod!
- 09-05-2008, 08:51 AM #4
Member
- Join Date
- Aug 2008
- Posts
- 41
- Rep Power
- 0
Oh my god! thanks MOD, when i use ActionPerform, everything work good! Thanks!!!
- 09-05-2008, 09:37 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You are welcome. :) Try to identify the best thing for each process. Actually there are lots possibilities to do the same thing.
If you have solve the problem, please mark it.
- 09-08-2008, 09:25 AM #6
Member
- Join Date
- Sep 2008
- Posts
- 7
- Rep Power
- 0
Im glad to be
Hello guys out there, Im so glad to be part of this as I surely can see that it is interesting... ;)
I have a problem with JComboBox, it is like this:
this is just a lil part of tha whole program
int[] arrayAugustMonthDays = new int[31];
(int count = 0; count < arrayAugustMonthDays.length; count++)
{
arrayAugustMonthDays[count] = count + 1;
}
JComboBox cboDate = new JComboBox(arrayAugustMonthDays);
but now it is giving me an error that it cannot resolve symbol
symbol : method parseInt (int[])
Please guys help!
- 09-08-2008, 09:45 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Somewhere in your code, use parseInt method which don't have a overloaded function with an int array. Only you can pass a string value. Can't say about more without looking at the code.
- 09-08-2008, 06:01 PM #8
Member
- Join Date
- Sep 2008
- Posts
- 31
- Rep Power
- 0
What i think is that you are adding to jcombobox string but it takes only int so convert it into string first.
- 09-09-2008, 04:03 AM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
It's better to show your code, at least part of it.
- 09-09-2008, 09:17 AM #10
Member
- Join Date
- Sep 2008
- Posts
- 7
- Rep Power
- 0
Not at all
No Im suppost to be adding an int array not a String data type. From what I've noticed is that it only accepts String array bcoz I've tried it and it works but now it will not work that way it is suppost to if I use String array. I've tried the Integer.parseInt and it still does gimme arrors. Somebody please help, this JComboBox is trouble.
- 09-09-2008, 10:41 AM #11
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Send the full code here. I hope it's not too long.
- 09-11-2008, 03:56 PM #12
Member
- Join Date
- Sep 2008
- Posts
- 7
- Rep Power
- 0
It works at last
Wow guys after a while I've managed to pull out a few strings, it's finally working...
Just a piece of my work:
Integer[] arrayAugustMonthDays = new Integer[31];
JComboBox cboDate;
for(int count = 0; count < arrayAugustMonthDays.length; count++)
{
//converts to integer and assigns these values to array elements:cool:
arrayAugustMonthDays[count] = new Integer(count + 1);
}
cboDate = new JComboBox(arrayAugustMonthDays);
- 09-12-2008, 09:40 AM #13
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Nice to see that. What's the purpose of the following code segment.
Java Code:new Integer(count + 1);
- 09-12-2008, 03:12 PM #14
Member
- Join Date
- Sep 2008
- Posts
- 7
- Rep Power
- 0
The purpose
I don't really know how to explain this but the purpose of this code "new Integer(count + 1);" is that it is actually enabling the array to accept the the calculated value as integer as you can see from the code 'count' which start from 0 plus 1 and keeps on increasing untill count < arrayAugustMonthDays.length.
- 09-12-2008, 05:46 PM #15
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Ok, simply use the following line of code and see what happen in your application.
Java Code:arrayAugustMonthDays[count] = (count + 1);
- 09-15-2008, 08:39 AM #16
Member
- Join Date
- Sep 2008
- Posts
- 7
- Rep Power
- 0
Not working
When I use the bellow code I get an error; 'Incompatible types'
arrayAugustMonthDays[count] = (count + 1);
And this one is working just fine;
arrayAugustMonthDays[count] = new Integer(count + 1);:)
- 09-15-2008, 11:26 AM #17
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yes, it should be. I hope better to read more about arrays. :)
Similar Threads
-
jComboBox and database
By pravin2008 in forum AWT / SwingReplies: 3Last Post: 08-25-2008, 04:08 PM -
JComboBox
By Fosters in forum AWT / SwingReplies: 0Last Post: 08-10-2008, 01:22 PM -
JComboBox setDisabledTextColor
By Jack in forum AWT / SwingReplies: 2Last Post: 07-02-2007, 05:32 AM -
Help with jComboBox
By Marcus in forum AWT / SwingReplies: 2Last Post: 07-01-2007, 11:08 PM -
jcombobox
By Freddie in forum AWT / SwingReplies: 4Last Post: 05-11-2007, 12:48 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks