This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Putting text from txt file straight into JComboBox  RSS feed

 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two classes - One is Read.java and the other is Display.java

Read.java looks like this




Display.java looks like this:



Instead of having it so it displays the id's to the console,is there a way I can set it straight up to the combo box?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alice Hampton wrote:
Instead of having it so it displays the id's to the console,is there a way I can set it straight up to the combo box?

Sure.
1) Read file
2) Extract data
3) Strore data in an appropriate model
4) Pass model to JComboBox

Recommended reading: http://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created the DefaultComboBoxModel and a Vector to hold the id's in. I just need to put the Vector <String>myVector into the DefaultComboBoxModel now
 
Rob Camick
Ranch Hand
Posts: 2800
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there a way I can set it straight up to the combo box?


Did you read the JComboBox API? Did you find an appropriate constructor that you might be able to use. Or did you find a method that allows you to add/insert items?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!