Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Default property on show on a  RSS feed

 
Fernando Dominguez
Ranch Hand
Posts: 108
Debian Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • 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
 
Rob Camick
Ranch Hand
Posts: 2753
11
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.

 
Fred Kleinschmidt
Bartender
Posts: 507
3
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 108
Debian Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot to both of you for the quick reply.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!