public static void TEXT_BASED_COMPONENTS()
{
ItsNatDocument itsNatDoc = null;
ItsNatComponentManager componentMgr = itsNatDoc.getItsNatComponentManager();
final ItsNatHTMLInputText inputComp = (ItsNatHTMLInputText)componentMgr.createItsNatComponentById("inputId");
inputComp.setText("Change this text and lost the focus");
EventListener evtListener = new EventListener()
{
public void handleEvent(Event evt)
{
System.out.println("Text changed: " + inputComp.getHTMLInputElement().getValue());
// Alternative: inputComp.getText();
}
};
inputComp.addEventListener("change",evtListener);
DocumentListener docListener = new DocumentListener()
{
public void insertUpdate(DocumentEvent e)
{
javax.swing.text.Document docModel = e.getDocument();
int offset = e.getOffset();
int len = e.getLength();
try
{
System.out.println("Inserted, pos " + offset + "," + len + " chars,\"" + docModel.getText(offset,len) + "\"");
}
catch(BadLocationException ex)
{
throw new RuntimeException(ex);
}
}
public void removeUpdate(DocumentEvent e)
{
javax.swing.text.Document docModel = e.getDocument();
int offset = e.getOffset();
int len = e.getLength();
System.out.println("Removedm, pos " + offset + "," + len + " chars");
}
public void changedUpdate(DocumentEvent e)
{
// A PlainDocument has no attributes
}
};
PlainDocument dataModel = (PlainDocument)inputComp.getDocument();
dataModel.addDocumentListener(docListener);
inputComp.focus();
inputComp.select();
}