• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

combobox

 
praveen shinde
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I presume you are familiar with database access?
 
praveen shinde
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10976
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
praveen shinde
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1951
7
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic