Results 1 to 5 of 5
  1. #1
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    3

    Default Adding null selection to a Combobox

    Hi,

    I have an Enum say Type..

    And when I create a new JComboBox with JComboBox(Type.values), I see that the ComboBox includes the values in my Enum. But I also want one empty field in my ComboBox. How can I do it ?

    Thank you..

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Adding null selection to a Combobox

    Don't use the JComboBox constructor that takes arrays. Instead create a DefaultComboBoxModel object and add your items one at a time, including an empty String, "", and with a for loop, all the items held by the enum, and then use this model for your JComboBox.

  3. #3
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    3

    Default Re: Adding null selection to a Combobox

    Thanks.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Adding null selection to a Combobox

    You're welcome.

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

    Default Re: Adding null selection to a 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. Replies: 1
    Last Post: 12-11-2011, 11:59 AM
  2. Table filtering base on selection in a combobox
    By new2java2009 in forum New To Java
    Replies: 10
    Last Post: 04-27-2011, 10:20 PM
  3. Replies: 6
    Last Post: 05-19-2010, 12:26 AM
  4. Replies: 2
    Last Post: 04-28-2009, 04:52 AM
  5. [SOLVED] Adding ComboBox
    By impact in forum New To Java
    Replies: 2
    Last Post: 05-02-2008, 08:43 PM

Posting Permissions

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