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 806001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:10:34+00:00 2026-05-15T00:10:34+00:00

the issue i mentioned in this post is actually happening because of cross threading

  • 0

the issue i mentioned in this post is actually happening because of cross threading GUI issues (i hope).

could you help me with Java version of action delegate please?

in C# it is done as this inline:

        this.Invoke(new Action(delegate()
        {...}));

how is this achived in Java?

thank you.

public class processChatMessage implements Observer {

    public void update(Observable o, Object obj) {


        System.out.println("class class class" + obj.getClass());

        if (obj instanceof String){

            String msg = (String)obj;

            formatChatHeader(chatHeader.Away, msg);

            jlStatusBar.setText("Message Received");

            // Show chat form
            setVisibility();

        }
    }
}

processChatMessage is invoked by a separate thread triggered by receiving new data from a remote node.

and i think the error is being produced as it trying to update GUI controls.

do you think this is the reason? i ask because im new to Java and C#, but this is what is going on i think.

SOLUTION:

public class processChatMessage implements Observer {

    public void update(Observable o, Object obj) {

        if (obj instanceof String){

            final String msg = (String)obj;

            try {

                SwingUtilities.invokeAndWait(new Runnable( ) {

                    public void run( ) {

                        formatChatHeader(chatHeader.Away, msg);
                        jlStatusBar.setText("Message Received");
                        setVisibility();
                    }
                });
            } catch (InterruptedException e){

            } catch (InvocationTargetException e){

            }
        }
    }
}
  • 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-05-15T00:10:35+00:00Added an answer on May 15, 2026 at 12:10 am

    The nearest equivalent would probably be the Runnable interface – basically a single-method interface with a method taking no parameters and returning no value. You can use an anonymous inner class to achieve an effect something like anonymous methods:

    executeRunnable(new Runnable() {
        public void run() {
            // Do stuff here
        }
    });
    

    Yes, it’s a bit verbose… but hopefully Java 7 closures will come to the rescue, eventually 🙂

    Now, that’s the general idea of the Action delegate. In this particular instance you should look at SwingUtilities.invokeLater(Runnable) and SwingUtilities.invokeAndWait(Runnable) as the rough equivalent of Control.BeginInvoke and Control.Invoke respectively.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this issue being mentioned before, but resolutions there didn't apply. I'm having
With help of this post and this tutorial I have managed to integrate Facebook
With the help of some very gracious stackoverflow contributors in this post , I
Issue When benchmarking a simple QuickSort implementation in Java, I faced unexpected humps in
This issue came up when I got different records counts for what I thought
The issue that prompted me to ask this is a web form that was
It appears that glColorMaterial() is absent from OpenGL ES . According to this post
I'm really unsure if this is even possible but we have an issue where
I think I understand why this is happening, but I am not sure how
I have alluded to this issue in my other question , but i think

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.