0

How to set a comboitem as selected in auto drop option

asked 2013-06-18 16:57:12 +0800

Mangapathi gravatar image Mangapathi
11 3

updated 2013-06-19 04:50:36 +0800

Hi,

I am rendering data into combobox as below.

public void fillComboBox(Combobox combobox, List<valuelabel> list) {

combobox.setModel(new SimpleListModel(list) {
    protected boolean inSubModel(Object key, Object value) {
        String idx = key.toString();
        ValueLabel myItem = (ValueLabel)value;
        return idx.length() > 0 && myItem.getLabel().startsWith(idx);
    }
});

combobox.setItemRenderer(new ComboitemRenderer () {
    public void render(Comboitem item, Object data, int count) throws Exception {
        ValueLabel valueLabel = (ValueLabel)data;
        item.setLabel(valueLabel.getLabel());
        item.setValue(valueLabel.getValue());
    }
});

}

How to set a value(comboitem) as selected true ? Please suggest me how to do this ?

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2013-06-18 17:44:56 +0800

eudsonbambo gravatar image eudsonbambo flag of Mozambique
30 2
http://eudsonbambo.blogsp...

Hello.

Since you rendering items data to your combobox dynamical you will have to decide wich is the coboitem that have to be defaulted selected so in order to do that i think i may have to put a if in you code and into you if you mas do: item.parent.selectedItem = item. Look at my code bellow:

<combobox >
 <comboitem label="Teste"></comboitem>
 <comboitem label="Joao" onCreate="self.parent.selectedItem = self"></comboitem>
</combobox>

Its very simple but its what you want.

In case that you know the index of the comboitem you want to be selected by default or that have the conditions to be setted to selected = true you can do it directly at the combobox by doing this: onCreate = "self.selectedIndex = indexThatYouPretendToBeSelected"

Hope it helps

link publish delete flag offensive edit
0
link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2013-06-18 16:57:12 +0800

Seen: 34 times

Last updated: Jun 19 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More