Results 1 to 9 of 9
  1. #1
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default How to create dynamic string object???

    Actually i am using a JComboBox that lists a set of items... like.
    Java Code:
    jComboBox1.setModel(new DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
    this is a static way of assigning items to the list of JComboBox..

    Now my requirements is that the items to be held by this JComboBox has to be fetched from a table that is dynamic in nature i.e., its content do update..

    so i need to update the list of items in the combobox from within the constructor.. for which i need to create an string object dynamically !! something like..

    Java Code:
    while(resultset.next()){
        String str[] = new String[]{resultset.getObject(1).toString()[COLOR="Red"]+more contents added with each iteration..[/COLOR]};
    }
    please suggest :confused:
    The Quieter you become the more you are able to hear !

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by Stephen Douglas View Post
    please suggest :confused:

    looke here JComboBox (Java Platform SE 6) you coud either use addItem or if you use a collection to fill the jcombobox you can add the new elements to the collection.

  3. #3
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default

    thnx :) It worked !!!!!!
    But isn't there any way we can dynamically create the string object.??????
    :rolleyes:
    The Quieter you become the more you are able to hear !

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

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Stephen Douglas View Post
    please suggest :confused:
    I'd use the JComboBox constructor that takes a Vector of objects. It is much easier to fill a Vector with (an unknown amount of ) data from a database than an array (fixed size issues etc.) So basically it runs like this:

    - create an (empty) Vector;
    - fill the Vector from the database;
    - create a JComboBox with the Vector.

    kind regards,

    Jos

  6. #6
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default

    By the way, what do you mean precisely by "dynamically create the String object"?
    I guess i have expressed the exact requirement with a possible example in my very first post. :)
    The Quieter you become the more you are able to hear !

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

    Default

    Quote Originally Posted by Stephen Douglas View Post
    I guess i have expressed the exact requirement with a possible example in my very first post. :)
    I saw that; I was wondering why you re-asked as you've been given several usable solutions.

  8. #8
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default

    I was wondering why you re-asked as you've been given several usable solutions.
    It is not about the available options...(Obviuosly my purpose is solved. and thnx for that :));; In my opinion you learn new things when you face new problems.. sO i am curious to know if the solution is possible the other way also. :rolleyes:
    The Quieter you become the more you are able to hear !

  9. #9
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    6

Similar Threads

  1. Create a CLOB object with the string value
    By oshoarun in forum JDBC
    Replies: 1
    Last Post: 03-18-2010, 07:36 PM
  2. create object with name from string
    By skandalouz in forum New To Java
    Replies: 7
    Last Post: 12-06-2009, 12:40 AM
  3. [SOLVED] Dynamic String -> Date Handeling
    By vagetoanima in forum Advanced Java
    Replies: 2
    Last Post: 03-31-2009, 07:43 PM
  4. How to create Dynamic application using J2ME?
    By sharmaj2me in forum CLDC and MIDP
    Replies: 1
    Last Post: 01-31-2009, 04:19 PM
  5. Replies: 1
    Last Post: 04-09-2008, 03:15 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
  •