how to get selected item from rendered combobox?

asked 2014-08-27 07:53:07 +0800

demizon gravatar image demizon
169 1 6

Hi, I have created combobox of MyClass items, each item has attribute "name", which is being displayed in combobox via renderer. My problem is, that I am getting null when I call


its null. But when I call


i get the proper index of selected item.

This is way, I create combobox:

Combobox combobox = new Combobox();
MyRenderer myRenderer = new MyRenderer();
combobox.setModel(new ListModelList<MyClass>(myClassList));

MyRenderer class:

public class MyRenderer implements ComboitemRenderer {

    public void render(Comboitem item, Object data, int index) throws Exception {
        item.setLabel(((MyClass) data).getName());

Can someone please explain me, where could be possible problem, or how to get selected item from combobox properly?


delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2014-08-27 08:13:03 +0800

chillworld gravatar image chillworld flag of Belgium
5322 4 9

Try this because you have an model behind the combobox.


Greetz chill.

link publish delete flag offensive edit


hmm, when i write combobox.getModel() i dont have method getSelection() in possible methods list.

demizon ( 2014-08-27 08:36:18 +0800 )edit

now i noticed that something is wrong with myRenderer...because when i dont use it i can get selected item without problems... but in such case items in combobox are not showing in readable format (just in string value of MyClass object, not name attribute)

demizon ( 2014-08-27 08:38:55 +0800 )edit

any idea what I am doing wrong plz?

demizon ( 2014-08-27 10:12:18 +0800 )edit

cast your model to ListModelList and you have the method. When you don't see the name your renderer isn't applied Try invalidate the combobox

chillworld ( 2014-08-27 11:53:40 +0800 )edit

it worked! thank you!

demizon ( 2014-08-27 13:37:48 +0800 )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

1 follower



Asked: 2014-08-27 07:53:07 +0800

Seen: 58 times

Last updated: Aug 27 '14

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