Hello.
I try to selected a key value out of map of key/value-pairs.
Everything works fine, but the ComboBox shows after the selection of a
key/value pair the key/value pair and not just the selected key.
Why?
How can I force the ComboBox to completely revalidate the model?
Here is my code:
/**
*
*/
package gui;
import java.util.HashMap;
import java.util.Map;
import shared.Pair;
import com.ulcjava.base.application.IComboBoxModel;
import com.ulcjava.base.application.ULCComboBox;
import com.ulcjava.base.application.event.ActionEvent;
import com.ulcjava.base.application.event.IActionListener;
import com.ulcjava.base.application.event.IListDataListener;
/**
* @author armin.kurz
*
*/
public class MyComboBox extends ULCComboBox
{
private class MyComboBoxModel implements IComboBoxModel
{
private final Map m_map;
private Object m_selected = null;
/**
* @param m_map
*/
public MyComboBoxModel(final Map map)
{
this.m_map = new HashMap(map);
}
/* (non-Javadoc)
* @see
com.ulcjava.base.application.IComboBoxModel#getSelectedItem()
*/
public Object getSelectedItem()
{
return m_selected;
}
/* (non-Javadoc)
* @see
com.ulcjava.base.application.IComboBoxModel#setSelectedItem(java.lang.Object)
*/
public void setSelectedItem(Object item)
{
Object selected = item;
if (item instanceof Pair)
{
selected = ((Pair)item).getKey();
}
else
{
selected = item;
}
m_selected = selected;
}
/* (non-Javadoc)
* @see
com.ulcjava.base.application.IListModel#getElementAt(int)
*/
public Object getElementAt(int index)
{
Object key = this.m_map.keySet().toArray()[index];
if (null != key)
{
Object value = this.m_map.get(key);
return new Pair(key, value);
}
return null;
}
/* (non-Javadoc)
* @see com.ulcjava.base.application.IListModel#getSize()
*/
public int getSize()
{
return this.m_map.size();
}
public void addListDataListener(IListDataListener listener) {
// TODO Auto-generated method stub
}
public void removeListDataListener(IListDataListener listener) {
// TODO Auto-generated method stub
}
}
/**
* @param items
*/
public MyComboBox(final Map items)
{
super();
this.setModel(new MyComboBoxModel(items));
this.addActionListener(new IActionListener(){
public void actionPerformed(ActionEvent event) {
ULCComboBox source = (ULCComboBox) event.getSource();
System.out.println("new item chosen: "
+ source.getSelectedItem());
}
});
}
}
Regards
Armin Kurz
--
Armin Kurz
Entwicklung
Büro Süd:
E/B/D Integration GmbH
Hauptstr. 67
82327 Tutzing
Tel: +49 (8158) 9 0766-0
Fax: +49 (8158) 9 0766-99
[EMAIL PROTECTED]
http://www.ebd-integration.de
_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer