• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Default property on show on a

 
Ranch Hand
Posts: 111
Eclipse IDE Firefox Browser Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,
My reason for writing here is to find out if there is a way to tell a JComboBox to display one property of the bean it is holding.

My JComboBox holds a List of the Bean <Producto> . It is currently displaying the whole properties of the Bean on the screen

This way

codigo=1;descripcion=A;categoria=y;
codigo=2;descripciĆ³n=B;categoria=z

and so on
is there any any way to tell the JComboBox to display one property only.
I mean, for example description



Thanks in advance
 
Rancher
Posts: 3324
32
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, when you post code you should be using the "Code" button to mark the code. Don't add your own HTML tags. As you can see the tags did nothing.

if there is a way to tell a JComboBox to display one property of the bean it is holding.



The best way is to create a custom renderer to display the property.

Check out Combo Box With Custom Renderer for a couple of examples.

 
Bartender
Posts: 732
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JComboBox will display whatever your class's toString() method returns. So you either have to use a custom renderer (as Rob Camick mentioned), or if you don't need the toString() method to return the whole property list, you can change it to just return the String you want to see in the ComboBox.
 
Fernando Dominguez
Ranch Hand
Posts: 111
Eclipse IDE Firefox Browser Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot to both of you for the quick reply.
 
"To do good, you actually have to do something." -- Yvon Chouinard
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic