Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: jcombobox custom renderer

Reply
Thread Tools

Re: jcombobox custom renderer

 
 
Albert
Guest
Posts: n/a
 
      03-26-2009
Mark a écrit :
> I want to display some business objects (Sections in this case) in a
> jcombobox rather than strings and I've been able to get the drop down
> list to successfully display the necessary text like so:
>
> sectionComboBox.setRenderer(new DefaultListCellRenderer() {
> public Component getListCellRendererComponent(JList list, Object value,
> int index, boolean isSelected, boolean cellHasFocus) {
> super.getListCellRendererComponent(list, value, index,
> isSelected,
>
> cellHasFocus);
>
> if (value instanceof Section) {
> Section s = (Section)value;
> setText(s.getDescription());
> }
>
> return this;
> }
> });
>
> but the text in the *editor* is displayed as
> com.mms.sourceit.server.Section[id=1] (the value of Section.toString())
> rather than Section.getDescription().
>
> Does anyone know what I need to do to get the jcombobox editor to
> display the Section's description?


My guess is that the editor part of the jcombobox is a jtextfield, so
you don't have access to a Section in the renderer. You should detect
the case of editor with index == -1, and then get the selectedItem from
the combobox to get the section.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Different height at JComboBox editor and renderer Beaned Java 0 08-25-2006 05:38 PM
JComboBox as a Cell Renderer in a table column question noident@my-deja.com Java 2 07-11-2006 11:21 PM
[JTable] Alignment in custom cell renderer Branko Kaucic Java 4 09-13-2005 07:03 AM
Updating JTable Cells with Custom Renderer Bryan R. Meyer Java 4 09-06-2004 06:01 AM
Different Renderer type per row in same column of JTable? RobE Java 2 08-12-2003 06:12 AM



Advertisments