Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jComboBox with Image

 
Saakshi Dikshit
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir my database contains path of images that I want my jComboBox to diaplay. I have written the following code but it does not work for comboBox but works fine when I display image on jLabel etc. Kindly tell me how should I go about this


 
Campbell Ritchie
Marshal
Posts: 52664
122
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Always use code tags; I added them for you and you can see it looks a lot better, and you have lost the ugly effect, too.
Please explain what happens; we need to know more than you have told us. What actually appears on the combo box? A combo box is intended to display text, principally.
 
Rob Camick
Ranch Hand
Posts: 2703
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to use a custom renderer to display the image. Read the JCombBox API and you will find a link to the Swing tutorial on "How to Use Combo Boxes" which explain what a renderer is and give you an example of a renderer to display an image.
 
Saakshi Dikshit
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir nothing is displayed in the Combo Box when the above code is run.
 
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
Saakshi Dikshit wrote:Sir nothing is displayed in the Combo Box when the above code is run.

Did you check out the How to use ... section which Rob pointed out to you? If yes, post your SSCCE code which uses a renderer
 
Saakshi Dikshit
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I removed the jLabel line from between and then it worked out fine....
 
Power corrupts. Absolute power xxxxxxxxxxxxxxxx is kinda neat.
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!