This week's book giveaway is in the Open Source forum.
We're giving away four copies of Programmers Guide to Apache Thrift and have Randy Abernethy on-line!
See this thread for details.
Win a copy of Programmers Guide to Apache Thrift this week in the Open Source forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

JCombobox doesn't display list of items  RSS feed

 
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JCombobox is in a Jdialog with 758 lines; I will display it entirely if requested; the constructor shows what I consider is important; how is the list set up and a mouse listener that allows the debugger to verify that the list is correct. I have searched the internet without luck.
 
Rancher
Posts: 3040
22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have no idea what this code does. For one thing I don't see where you add the combo box to the panel.

Post a proper SSCCE that demonstrates the problem.
 
Alejandro Barrero
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Alejandro Barrero
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help; I presented the entire class.
 
Marshal
Posts: 64471
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Alejandro Barrero wrote:. . . I presented the entire class.

Afraid that won't help; RC asked for an SSCCE please read that link.
 
Alejandro Barrero
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please forgive my ignorance; I understand then an SSCCE is a "Short, Self Contained, Correct (Compilable), Example"; the code I added is not short but it is a "Self Contained, Correct (Compilable), Example"; please explain how I can modify the code presented to make it acceptable for review; is it acceptable to present only the methods that use the JCombobox?
 
Rob Camick
Rancher
Posts: 3040
22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your question is about displaying items in a combo box.

So for a SSCCE all you need is:

1. a JFrame
2. a JComboBox
3. a JButton with an ActionListener.

When you click the button you add some hard coded items to the combo box.

Learn the basics of how dynamically adding items to a combo box works with a simple program. It is much easier to understand the concept with 20-30 lines of code.

If that code works, then great you've demonstrated you understand how to add items to a combo box.  If it doesn't work then you have a SSCCE to post in the forum.

Then once the above code works (either on your own or with our help) you add some items that you get dynamically from some other source (a file or a database).

Then once you understand that there is no special code needed to use the addItem() method of the combo box you debug your program to figure out what you are doing differently.

Problem solving is all about simplifying the problem. If you can't simplify the problem then you don't understand your requirement or the code you are writing.
 
Bartender
Posts: 703
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have scores opf calls like this:Don't do that! There are numerous better ways that don't keep creating multiple instances of the same color. The simplest (for a beginner) is to create that color once and assign it to an instance variable, then re-use that instance variable:

Even better, use the UIManager class to specify what default attributes you want for your components; then you do not have to make all those calls at all.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!