public static void LISTS_COMBO_BOXES()
{
ItsNatDocument itsNatDoc = null;
ItsNatComponentManager componentMgr = itsNatDoc.getItsNatComponentManager();
ItsNatHTMLSelectComboBox comboComp = (ItsNatHTMLSelectComboBox)componentMgr.createItsNatComponentById("compId");
DefaultComboBoxModel dataModel = (DefaultComboBoxModel)comboComp.getComboBoxModel();
dataModel.addElement("Madrid");
dataModel.addElement("Sevilla");
dataModel.addElement("Segovia");
dataModel.addElement("Barcelona");
dataModel.addElement("Oviedo");
dataModel.addElement("Valencia");
dataModel.setSelectedItem("Segovia");
EventListener evtListener = new EventListener()
{
public void handleEvent(Event evt)
{
System.out.println(evt.getCurrentTarget() + " " + evt.getType());
}
};
comboComp.addEventListener("change",evtListener);
ListDataListener dataListener = new ListDataListener()
{
public void intervalAdded(ListDataEvent e)
{
listChangedLog(e);
}
public void intervalRemoved(ListDataEvent e)
{
listChangedLog(e);
}
public void contentsChanged(ListDataEvent e)
{
listChangedLog(e);
}
public void listChangedLog(ListDataEvent e)
{
int index0 = e.getIndex0();
int index1 = e.getIndex1();
String action = "";
int type = e.getType();
switch(type)
{
case ListDataEvent.INTERVAL_ADDED: action = "Added"; break;
case ListDataEvent.INTERVAL_REMOVED: action = "Removed"; break;
case ListDataEvent.CONTENTS_CHANGED: action = "Changed"; break;
}
String interval = "";
if (index0 != -1)
interval = " interval " + index0 + "-" + index1;
System.out.println(action + " " + interval);
}
};
dataModel.addListDataListener(dataListener);
ItemListener itemListener = new ItemListener()
{
public void itemStateChanged(ItemEvent e)
{
String fact;
int state = e.getStateChange();
if (state == ItemEvent.SELECTED)
fact = "Selected";
else
fact = "Deselected";
System.out.println(fact + " " + e.getItem());
}
};
comboComp.addItemListener(itemListener);
}