Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 49 of 49

Thread: JComboBox issue. If user selects any item do this... (if statment)

  1. #26
    Member
    Join Date
    Mar 2012
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    OK, but the items are stored in the database, is there a way that i don't need to add a blank row in the database

  2. #27
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    You can add the new blank item at runtime, as well as the items from the database.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #28
    Member
    Join Date
    Mar 2012
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    i think adding a blank item in runtime would be better. How would i be able to do that?Sorry.

    Thanks
    Last edited by kpat; April 3rd, 2012 at 09:11 AM.

  4. #29
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    Use the JComboBox.insertItemAt(Object,0); method.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  5. #30
    Member
    Join Date
    Mar 2012
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    problem solved
    Last edited by kpat; April 8th, 2012 at 07:27 AM.

  6. #31
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    i got this error java.lang.NullPointerException?
    What variable has the null value?
    If you don't understand my answer, don't ignore it, ask a question.

  7. The Following User Says Thank You to Norm For This Useful Post:

    kpat (April 3rd, 2012)

  8. #32
    Member
    Join Date
    Mar 2012
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Talking Re: JComboBox issue. If user selects any item do this... (if statment)

    I managed to fix the problem, after some playing around thanks to both of you.

    Norm & aussiemcgr thank you both for your help and support when i had a problem.
    Last edited by kpat; April 3rd, 2012 at 11:06 AM.

  9. #33
    Member
    Join Date
    Mar 2012
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    problem solved
    Last edited by kpat; April 8th, 2012 at 07:26 AM.

  10. #34
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    Please make a small, simple program that compiles, executes and shows the problem.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #35
    Member
    Join Date
    Mar 2012
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    problem solved
    Last edited by kpat; April 8th, 2012 at 07:26 AM.

  12. #36
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    When you wanted to insert the empty String into the list.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #37
    Member
    Join Date
    Mar 2012
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    problem solved
    Last edited by kpat; April 8th, 2012 at 07:27 AM.

  14. #38
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    What happens when you execute the insertItemAt("",0) method?
    Where is the empty String added?
    If you don't understand my answer, don't ignore it, ask a question.

  15. #39
    Member
    Join Date
    Mar 2012
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    problem solved
    Last edited by kpat; April 8th, 2012 at 07:27 AM.

  16. #40
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    Can you show an example by making a list and adding comments to describe the problem:
    first item << can see this one
    second item
    third item
    If you don't understand my answer, don't ignore it, ask a question.

  17. #41
    Member
    Join Date
    Mar 2012
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    problem solved
    Last edited by kpat; April 8th, 2012 at 07:26 AM.

  18. #42
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    Have you tried any of the JComboBox class's methods to change what is shown?
    If you don't understand my answer, don't ignore it, ask a question.

  19. #43
    Member
    Join Date
    Mar 2012
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    yer but nothing. i tried messing around with the placing and setSelectedIndex(-1) and etc. any ideas?

  20. #44
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    I'd use one of the JComboBox methods.
    If you don't understand my answer, don't ignore it, ask a question.

  21. #45
    Member
    Join Date
    Mar 2012
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    problem solved
    Last edited by kpat; April 8th, 2012 at 07:26 AM.

  22. #46
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    Do you have the API doc? Read it looking for any methods that will do what you want. Try all that look useful with lots of different combinations of arguments and see if any of them do what you want.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #47
    Member
    Join Date
    Mar 2012
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    ok fine thanks

  24. #48
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    I think you will have to use one of the class's methods. You can experiment the same as I would have to experiment to find it. You will learn something by doing the experiments that will help you in the future.
    If you don't understand my answer, don't ignore it, ask a question.

  25. #49
    Member
    Join Date
    Mar 2012
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: JComboBox issue. If user selects any item do this... (if statment)

    problem solved thanks guys

Page 2 of 2 FirstFirst 12

Similar Threads

  1. If/Else Statment Help
    By aandcmedia in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 17th, 2012, 04:10 PM
  2. JComboBox selection not showing item from object array
    By oper125 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 24th, 2010, 06:31 AM
  3. Problem getting selected item as string from JComboBox
    By lost in forum AWT / Java Swing
    Replies: 1
    Last Post: October 26th, 2010, 03:22 AM
  4. drag item or insert item into new Jlabel in JPanel
    By qaromi in forum AWT / Java Swing
    Replies: 5
    Last Post: July 6th, 2010, 07:37 PM
  5. Switch Statment
    By 3XiLED in forum Java Theory & Questions
    Replies: 2
    Last Post: March 31st, 2010, 05:11 PM