aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes how to auto update jcombobox? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to auto update jcombobox?" Watch "how to auto update jcombobox?" New topic
Author

how to auto update jcombobox?

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
i apologies to making it confused...
i have removed all the unrelated code from my main class, here is formatted main class.
WelcomeScreen1.java
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
I can put all this together now, and, *very* seriously a lot of it is garbage, and should be thrown out.

hide/show? that type of coding disappeared in the last century - if you must toggle between screens,
use a CardLayout.

I've posted several times to get rid of the search function, and to add it later when you get the original
problem working.

So, unless you're prepared to post an opening screen with a textfield/comboBox/button, where the
comboBox is loaded from a database (include the db code, I can easily simulate an arraylist for it),
and the button, when clicked, will add whatever is in the textfield to the database, then subsequently
refreshing the comboBox with the newly added data, I can do no more - someone else may come along
and assist.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2

hide/show? that type of coding disappeared in the last century - if you must toggle between screens,
use a CardLayout.

i was not aware to that, i will replace that code, with cardlayout.

I've posted several times to get rid of the search function, and to add it later when you get the original
problem working.

okay, below is the display and display1 class, here combobox is added from database.

Display1.java


Display.java


rest of the classes, loadStudent, saveStudent, Db are same.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
it all works fine here.
I wrapped all ther classes together, so they could 'see' the simulated database.
you just need to put back the db code and it should work the same way.

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
michael,
with arraylist code is works fine here, but i just added the db part, and again the same problem, nothing i did i only added the db part, i mean just uncomment that, and commented the arraylist.
again i have to restart my application to see the last inserted value, not getting updated.
here is the code with db:-

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
you'll have to put in a bunch of System.out.println's (one at a time) starting at
line 49 d1.update()
to see where the program goes i.e. if the message is printed, move the println
to the next section. Eventually you should find where the message is not printed
so you can check that bit of code.

the code looks OK.
the only db stuff I've done was ages ago, in another language, where you had to
close the connection. That may be the same in java, don't know.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
instead of loading the resultset into combobox, if i load the arraylist, all works fine.
values are going into db.
but when i load resultset, the problem comes.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
well, i tried something, and it's worked, only one problem is in this approach.
what i did is:
in the nameValues(), instead of returning resultset, i added resultset to arraylist, and then i am returning arraylist, it's worked, but values in combobox are coming multiple times.
i mean the value which i entered last in coming once, but the earlier ones getting increased, might be some problem in loop..?
here is the method:


calling in the same way..
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
everything looks OK, and it must work OK, because it loads the newly saved data
if you close the app then reopen it.

the problem is when update() is called, so you'll just have to go through those steps
I posted earlier. you could also printout the resultSet size to see if there's any difference
between when the app opens, and when something is saved.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
finally done......
the problem was here:


thank you thank you thank you very much michael..
your help is very much appreciable..
Thank you
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> finally done.....

well done, I knew you'd get there in the end - mostly just a matter of putting things together in the right order.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2

well done, I knew you'd get there in the end - mostly just a matter of putting things together in the right order.

yes, and also because of your help..
so thanks agaiin michael..
 
 
subject: how to auto update jcombobox?