Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8983589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:52:40+00:00 2026-06-15T20:52:40+00:00

I have made a simple client using SMACK api and OpenFire on localhost. As

  • 0

I have made a simple client using SMACK api and OpenFire on localhost. As of now, I have two users say X and Y. Whenever anyone logs in to the client, there is a send button which sends a message to user Y. I’ve checked the XMPP debug manager and I’m able to send/receive messages there. However, I’m unable to display those messages in a JLabel that I have alloted for displaying the messages. If the User Y hits the send button, as per the functionality it sends a message to himself and that comes up on the JLabel. But when user X hits the send button, the message is received, however it is not displayed/updated on the Y’s JLabel.

Interestingly, everything works as it should with gtalk configuration.

The structure is as follows:

WelcomeUser.java:
Is the welcome form with username and password prompt. On hitting the login button :
it sets the ChatBoard class visible and passes on the username password to the constructor of ChatBoard.
Code:

chBoard=new ChatBoard(username.getText(),password.getText());
                chBoard.setVisible(true);
                setVisible(false);

Here is the code for ChatBoard.java:

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collection;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;

import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;

public class ChatBoard extends JFrame implements MessageListener {

    private static final long serialVersionUID = 1L;
    private JPanel contentPane;
    static String username, password;
    static XMPPConnection connection;
    private JTextField textField;
    static JLabel board = new JLabel("");
    static Chat chat;

    public void sendChat() {
        try {
            chat = connection.getChatManager().createChat(
                    "userY@my-pc/Smack", this);
            chat.sendMessage("Hello, This is " + username);
        } catch (XMPPException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }


    /**
     * Create the frame.
     */
    public ChatBoard(String user, String pass) {

        username = user;
        password = pass;

        ////  
                   ///JFrame creation code ommited for this thread.
        // ////////////////////////////////////////////

        XMPPConnection.DEBUG_ENABLED = true;

        ConnectionConfiguration config = new ConnectionConfiguration(
                "127.0.0.1");


        connection = new XMPPConnection(config);

        try {
            connection.connect();
            System.out.println("Connected...");
        } catch (XMPPException e) {

            e.printStackTrace();
            System.out.println("Not Connected. Error :" + e.getMessage());
        }

        try {
            connection.login(username, password);
            System.out.println("Logged in...");
        } catch (XMPPException e) {

            e.printStackTrace();
            System.out.println("Not Logged in. Error :" + e.getMessage());
        }

        Roster roster = connection.getRoster();
        Collection<RosterEntry> entries = roster.getEntries();

        System.out.println("\n\n" + entries.size() + " buddy(ies):");
        for (RosterEntry r : entries) {
            System.out.println(r.getUser());
        }

        // /////////////////////////////////

    }

    @Override
    public void processMessage(Chat arg0, Message arg1) {
        // TODO Auto-generated method stub

        board.setText(board.getText() + arg1.getBody());
        System.out.println(arg1.getFrom() + ":" + arg1.getBody().toString());

    }

}

I’m new to this, so forgive me if there are any silly mistakes. Your help would be really appreciated.

Misc. Details: OpenFire 3.7.1 on localhost with SMACK 3.2.2

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:52:41+00:00Added an answer on June 15, 2026 at 8:52 pm

    Have a look at the bottom of http://www.igniterealtime.org/builds/smack/docs/latest/documentation/messaging.html. For incoming chats from another user you have to override ChatManagerListener

    Can you set a breakpoint on processMessage and does it hit that breakpoint? If so it might just be a matter of making sure the:

    board.setText()
    

    occurs on the Swing event dispatch thread

    So try making your processMessage like this :

    @Override
    public void processMessage(Chat arg0, Message arg1) {
        // TODO Auto-generated method stub
    
        try
        {
            SwingUtilities.invokeAndWait(new Runnable()
            {
    
                @Override
                public void run()
                {
                    board.setText(board.getText() + arg1.getBody());
                }
            });
        }
        catch (InvocationTargetException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch (InterruptedException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println(arg1.getFrom() + ":" + arg1.getBody().toString());
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OK, I have made simple rectangular using OpenGL, and it looks pretty simple glNormal3f(0.0f,
I have made a simple test application for the issue, two winforms each containing
I currently have a Rails 3.0.10 app and I made two models with simple
I have a simple class that handles the connection being made between a client
I have made a simple server -client code in python socket programming. Client side
I have made simple encryption/decryption method in php that I'm trying to move to
I have made a simple chat application in PHP/Ajax/MySQL. I am regularly calling these
I have made a simple code for ajax to call a page but it
I have made a simple Line Chart: Which is showing 4 grid-lines at points
I have made a simple web-page including a couple of static pages, a css

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.