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

combobox

praveen shinde
Ranch Hand

Joined: Jun 03, 2009
Posts: 63
Hi ,
I have created a jframe which contains a combobox.
I want the combobox to be populated with data from a database as soon as the window/Jframe is displayed.
How to do this.
Any help is welcome.
Regards,
Praveen Shinde
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
I presume you are familiar with database access?
praveen shinde
Ranch Hand

Joined: Jun 03, 2009
Posts: 63
Hi Ritchie,
I am familar with database access.
My main problem is to display the data in the combo box as soon as the Jframe is opened.
regards,
Praveen
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

1) Subclass JComboBox
2) Provide a method called loadData which will connect to the DB, pull out required data and insert into the JComboBox. Make sure this happens in a separate thread .
3) Add your subclassed combo box instance to the frame.
4) Overide setVisible() in your frame instance
5) Invoke super.setVisible() and combo.loadData() in your overridden setVisible()

And yes. In future please UseAMeaningfulSubjectLine


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
praveen shinde
Ranch Hand

Joined: Jun 03, 2009
Posts: 63
Hi maneesh,
Thanks for the help.
I will try out your suggestions.
yes I will use more relevant headlines in future.
regards,
Praveen
praveen shinde
Ranch Hand

Joined: Jun 03, 2009
Posts: 63
Hello Maneesh,
I created a frame with 6 panel(without using drag n drop facility of Netbeans). I still cant see all the panels. I even tried adding a scrollbar.
Please help
Thanks
Praveen
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
is this just a continuation of your other thread?

http://www.coderanch.com/t/506199/GUI/java/panels-not-displayed-fullly-Jframe

if so, instead of encouraging everyone to play '20-guesses', why don't you post your code,
so we can see what you're doing (incorrectly).
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1779
    
    7

Maneesh Godbole wrote:1) Subclass JComboBox
2) Provide a method called loadData which will connect to the DB, pull out required data and insert into the JComboBox. Make sure this happens in a separate thread .
3) Add your subclassed combo box instance to the frame.
4) Overide setVisible() in your frame instance
5) Invoke super.setVisible() and combo.loadData() in your overridden setVisible()

And yes. In future please UseAMeaningfulSubjectLine


I'd prefer loading the data via a ComboBoxModel implementation, instead of tying a subclass of JComboBox directly (or indirectly) to a datasource via a custom loadData() method.

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: combobox