Hi Martin,
Nothing is jumping out at me as to why your textfield is not being updated. I have not worked much with Eclipse’'s GUI builder, is it possible that your textfield has not been instanciated before you call the setText() method? Below is a simple program that updates a textarea that you might want to take a look at for ideas:
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import javax.swing.JDialog;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class ParrotBotUI extends JDialog implements PacketListener {
private JScrollPane scrollPane = null;
private JTextArea textAreaConverstation = new JTextArea();
private XMPPConnection connection = null;
private Chat chat = null;
private PacketFilter filter = null;
private static String server = “localhost”;
private static String user = “test”;
private static String password = “test”;
public static void main(String[] args) {
new ParrotBotUI().squawk();
}
public ParrotBotUI() {
scrollPane = new JScrollPane(textAreaConverstation);
getContentPane().add(scrollPane);
setTitle(“ParrotBotUI”);
setSize(300, 200);
setVisible(true);
try {
//XMPPConnection.DEBUG_ENABLED = true;
connection = new XMPPConnection(server);
connection.login(user, password);
textAreaConverstation.append(“Connected”);
textAreaConverstation.append("\n");
filter = new PacketTypeFilter(Message.class);
connection.addPacketListener(this, filter);
} catch (XMPPException e) {
e.printStackTrace();
}
}
private void squawk() {
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public void processPacket(Packet packet) {
Message message = (Message) packet;
chat = connection.createChat(packet.getFrom());
try {
String body = message.getBody();
chat.sendMessage(body);
textAreaConverstation.append("<" + message.getFrom() + "> ");
textAreaConverstation.append(body);
textAreaConverstation.append("\n");
} catch (XMPPException e) {
e.printStackTrace();
}
}
}
/code
Hope that helps,
Ryan