Results 1 to 19 of 19
  1. #1
    efozdel is offline Member
    Join Date
    Jul 2010
    Posts
    22
    Rep Power
    0

    Default Add item to combobox permanently

    hi,
    I have a problem with comboboxes.. When I am trying to add an item to combobox using combobox.addItem(something); it is added to combobox but time I close and re-open the program again , combobox returns its original version. How could I add an item to combobox permanently. I mean when a item is added to combobox , I want that item to stay there whenever I close/open program..

    Thanks for your help in advance ..

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    805
    Rep Power
    6

    Default

    Please share your code so that we can see where it went wrong.
    Ramya:cool:

  3. #3
    efozdel is offline Member
    Join Date
    Jul 2010
    Posts
    22
    Rep Power
    0

    Default

    if(adding.bolge.isEmpty())
    {
    String bayii1=adding.bayii;
    adding.bayii = "";
    ta2.append(bayii1 + "Bayiisi Eklendi!!\n");
    cb7.setEditable(true);
    cb7.addItem(bayii1);

    }
    else if(adding.bayii.isEmpty())
    {
    String bolge1=adding.bolge;
    adding.bolge = "";
    ta2.append(bolge1 + "Bölgesi Eklendi!!\n");

    cb6.setEditable(true);
    cb6.addItem(bolge1);

    }

    Btw, I want to do this by not using database, it should be done at runtime..
    Last edited by efozdel; 07-09-2010 at 11:18 AM.

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

    Default

    Quote Originally Posted by efozdel View Post
    but time I close and re-open the program again , combobox returns its original version. How could I add an item to combobox permanently. I mean when a item is added to combobox , I want that item to stay there whenever I close/open program..
    i guess, the combobox is reinitialized when you close and re-open your program. if you save the new added items in the database or somewhere else the items will be reloaded when you open your program.

  5. #5
    efozdel is offline Member
    Join Date
    Jul 2010
    Posts
    22
    Rep Power
    0

    Default

    I havent seen database yet, that's why, I want to achieve it by not using database or file. is it possible to do it at runtime like I added other items on properties.

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

    Default

    You know of course that properties use files. One way or another, you're going to have to store something on disk; I see no way around this.

  7. #7
    efozdel is offline Member
    Join Date
    Jul 2010
    Posts
    22
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    You know of course that properties use files. One way or another, you're going to have to store something on disk; I see no way around this.
    then , is there any way to use same file properties use ? or any other solutions which can help me are appriciated...

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    is there any way to use same file properties use
    Do you mean the JVM's properties file? I don't know if all of the JVM's properties actually come from a file. No matter, You don't want to change that.
    Make you own properties file to store your data in.

  9. #9
    efozdel is offline Member
    Join Date
    Jul 2010
    Posts
    22
    Rep Power
    0

    Default

    I think there must be a way to save your data to combobox permanently without using file since same problem is occurred while removing data from combobox.

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

    Default

    Quote Originally Posted by efozdel View Post
    I think there must be a way to save your data to combobox permanently without using file since same problem is occurred while removing data from combobox.
    Think of it: if you don't want to use a file (which is permanent storage) you can't use a database either (also a file or more files), you can't use any 'registry' either (also a file and extremely platform dependent). Where do you want to store your data? In your computer's ventilator?

    kind regards,

    Jos
    Last edited by JosAH; 07-10-2010 at 02:50 PM.

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    The solution is NEVER to exit the program. Keep it running (in memory) and you don't have to use a file to save data in.
    There is a problem if the computer is shut down.

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

    Default

    Quote Originally Posted by Norm View Post
    The solution is NEVER to exit the program. Keep it running (in memory) and you don't have to use a file to save data in.
    There is a problem if the computer is shut down.
    Or add a device with an automatic gun coupled to an optical movement recognizer that shoots the villain that wants to flip the switch of pull the plug from the computer ...

    kind regards,

    Jos ;-)

  13. #13
    efozdel is offline Member
    Join Date
    Jul 2010
    Posts
    22
    Rep Power
    0

    Default

    I did not mean I dont wanna use file or any other memory location, I just wanted to say, is there any method which does it automatically on behalf of me like properties does. Because, I said before, when I deleted an item from combobox, after closing and restarting program, the deleted item comes again.That's why, I asked that question. Btw, I dont use ventilator, I am using wind power instead of it:)
    Last edited by efozdel; 07-10-2010 at 06:41 PM.

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

    Default

    I suppose you could create your own Properties object, but why not simply create and read a file as has been suggested, oh about 15 times now?

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

    Default

    Quote Originally Posted by efozdel View Post
    I did not mean I dont wanna use file or any other memory location
    To quote you from reply #9:

    I think there must be a way to save your data to combobox permanently without using file
    Please do make up your mind before asking questions here. Oh, and b.t.w. there's file IO and serialization so you can build your own persistency rules from that but there is no pre-cooked saveWhatIHaveInMind() method anywhere.

    kind regards,

    Jos

  16. #16
    efozdel is offline Member
    Join Date
    Jul 2010
    Posts
    22
    Rep Power
    0

    Default

    Thanks for your worthy thoughts and link you gave ..

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

    Default

    Quote Originally Posted by efozdel View Post
    Thanks for your worthy thoughts and link you gave ..
    So what are you going to do now? Are you going to use a Properties object (and if so, how)? or are you just going to save the state of your object to a file now? What suprises me is that you suddenly consider your thread [solved] without a new reason ...

    kind regards,

    Jos

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

    Default

    Yeah, properties is not really used for this. Better to use properties to say hold the default location of the file that actually holds this data and allow the program to override this perhaps with command line arguments.

  19. #19
    efozdel is offline Member
    Join Date
    Jul 2010
    Posts
    22
    Rep Power
    0

    Default

    in my first post, I have said sorry for my poor english . Since , sometimes it is not that easy to explain your feelings and thoughts in a different language to different people. In my thread, I wanted to learn , is there any method that adds data you write in at runtime nonvolatile. Here people said you should save your data to file or whatever it is called. Yeah , I actually tried and did it successfully but a new problem appears in that time. When you tried to remove something which are default values of combo box from the combo box , it fails . Then , I thought there should be adverse methods like addItem , removeItem to add and to remove data from the combo box permanently. However , I decided to believe there is not such methods like saveWhatIhaveinMymind :) since if professionals like you dont know it , there is not :)

Similar Threads

  1. Saving Objects Permanently?
    By ethann_91 in forum New To Java
    Replies: 1
    Last Post: 01-20-2010, 08:03 AM
  2. How to get the selected item from combox
    By man4ish in forum AWT / Swing
    Replies: 5
    Last Post: 12-30-2009, 10:29 AM
  3. Need Help combobox
    By kwink in forum AWT / Swing
    Replies: 3
    Last Post: 03-21-2009, 10:05 AM
  4. combobox
    By chandu.v in forum New To Java
    Replies: 2
    Last Post: 07-02-2008, 08:36 PM
  5. Storing data permanently
    By shaungoater in forum New To Java
    Replies: 2
    Last Post: 03-10-2008, 04:18 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
  •