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

jcombox value will be hidden and text show always  RSS feed

 
Avik Ghosh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We want to show text and select value in jcombobox.
We are using this code:


public class Item {
private String id;
private String description;

public Item(String id, String description)
{
this.id = id;
this.description = description;
}

public String getId()
{
return id;
}

public String getDescription()
{
return description;
}

public String toString()
{
return description;
}
}

public class ItemRenderer extends BasicComboBoxRenderer{
public Component getListCellRendererComponent(
JList list, Object value, int index,
boolean isSelected, boolean cellHasFocus)
{
super.getListCellRendererComponent(list, value, index,
isSelected, cellHasFocus);

if (value != null)
{
Item item = (Item)value;
setText( item.getDescription().toUpperCase() );
}

if (index == -1)
{
Item item = (Item)value;
setText( "" + item.getId() );
}


return this;
}

}



operator_typeBean oprTyp=new operator_typeBean();
oprTypComb = new JComboBox(oprTyp.fnFillCombo())
;
oprTypComb.setRenderer(new ItemRenderer());


But now the problem is when we select combobox any item,at that time text is not showing.
we want that value will be always hidden,every time text will be showing.
but combox.selectedItem will give the value not the text.
slide1.png
[Thumbnail for slide1.png]
in case of popup showing
slide2.png
[Thumbnail for slide2.png]
incase of selected
 
Rob Camick
Ranch Hand
Posts: 2752
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Get rid of the above code.

Or you can get rid of the custom renderer completely and just convert the description to upper case when you create the Item object.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!