Results 1 to 5 of 5
  1. #1
    iNko is offline Member
    Join Date
    Dec 2012
    Posts
    55
    Rep Power
    0

    Default Cant figure out how to write an if statement for combobox

    Hello, i have a form witch has 3 ComboBoxes 1 TextField and 1 TextArea.

    These ComboBoxes have values, but the first value in each box is a blank value (i made it this way).
    I need to check in my if statement, if even one value from these combo boxes are set for the first value (blank one).

    For textfield i just check like this - 'if (textfield.getText().isEmpty()'. Will this work for TextArea aswell? (i mean the isEmpty part).

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: Cant figure out how to write an if statement for combobox

    To get the selected item from JComboBox you can use getSelectedItem(). If your JComboBox items are strings can cast object returned by the getSelectedItem() method to string.

  3. #3
    iNko is offline Member
    Join Date
    Dec 2012
    Posts
    55
    Rep Power
    0

    Default Re: Cant figure out how to write an if statement for combobox

    Thanks, it works.

    Used like this:
    Java Code:
    if (combobox.getSelectedItem().equals(" ")){
    }
    (My first item is " ")
    Last edited by iNko; 12-08-2012 at 06:02 PM.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,196
    Rep Power
    19

    Default Re: Cant figure out how to write an if statement for combobox

    Or if you're on Java SE 7 you can use Generics and have no need for casting.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,196
    Rep Power
    19

    Default Re: Cant figure out how to write an if statement for combobox

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. how to embed combobox,checbox in JTable read write to database
    By scorpion.poison in forum New To Java
    Replies: 4
    Last Post: 08-30-2012, 10:52 AM
  2. Replies: 7
    Last Post: 02-14-2012, 10:12 AM
  3. Can't figure out how to write this program.
    By Quinn in forum New To Java
    Replies: 18
    Last Post: 05-18-2011, 09:04 PM
  4. Replies: 6
    Last Post: 03-31-2011, 03:33 PM
  5. How to Write this if statement?
    By PeterFeng in forum New To Java
    Replies: 1
    Last Post: 01-14-2009, 07:11 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
  •