Results 1 to 17 of 17
  1. #1
    hungleon88 is offline Member
    Join Date
    Aug 2008
    Posts
    41
    Rep Power
    0

    Default 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!!

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  3. #3
    hungleon88 is offline Member
    Join Date
    Aug 2008
    Posts
    41
    Rep Power
    0

    Default

    Oh, i use ItemStateChange for this.
    I 'll try Action Listener.
    Thanks Mod!

  4. #4
    hungleon88 is offline Member
    Join Date
    Aug 2008
    Posts
    41
    Rep Power
    0

    Default

    Oh my god! thanks MOD, when i use ActionPerform, everything work good! Thanks!!!

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    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.

  6. #6
    t.Donas is offline Member
    Join Date
    Sep 2008
    Posts
    7
    Rep Power
    0

    Default 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!

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    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.

  8. #8
    khajalid is offline Member
    Join Date
    Sep 2008
    Posts
    31
    Rep Power
    0

    Default

    What i think is that you are adding to jcombobox string but it takes only int so convert it into string first.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  10. #10
    t.Donas is offline Member
    Join Date
    Sep 2008
    Posts
    7
    Rep Power
    0

    Question 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.

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  12. #12
    t.Donas is offline Member
    Join Date
    Sep 2008
    Posts
    7
    Rep Power
    0

    Wink 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);

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Nice to see that. What's the purpose of the following code segment.

    Java Code:
    new Integer(count + 1);

  14. #14
    t.Donas is offline Member
    Join Date
    Sep 2008
    Posts
    7
    Rep Power
    0

    Default 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.

  15. #15
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Ok, simply use the following line of code and see what happen in your application.

    Java Code:
    arrayAugustMonthDays[count] = (count + 1);

  16. #16
    t.Donas is offline Member
    Join Date
    Sep 2008
    Posts
    7
    Rep Power
    0

    Default 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);:)

  17. #17
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. jComboBox and database
    By pravin2008 in forum AWT / Swing
    Replies: 3
    Last Post: 08-25-2008, 04:08 PM
  2. JComboBox
    By Fosters in forum AWT / Swing
    Replies: 0
    Last Post: 08-10-2008, 01:22 PM
  3. JComboBox setDisabledTextColor
    By Jack in forum AWT / Swing
    Replies: 2
    Last Post: 07-02-2007, 05:32 AM
  4. Help with jComboBox
    By Marcus in forum AWT / Swing
    Replies: 2
    Last Post: 07-01-2007, 11:08 PM
  5. jcombobox
    By Freddie in forum AWT / Swing
    Replies: 4
    Last Post: 05-11-2007, 12:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •