I have a class that has a text area. the code is as follows

package view;

import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;


public class LabelStatus extends JPanel {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    JFrame frame; 
    public static JTextArea test;
    JLabel title;


    public LabelStatus() {
        JLabel title = new JLabel ("INCOMING MESSAGES  ",JLabel.CENTER);
        title.setFont(new Font ("Serif", Font.BOLD,30));
        this.add(title); 
        GridBagConstraints k = new GridBagConstraints();       
        k.gridx = 10;
        k.gridy = 10; 
        test = new JTextArea(60,60);
        test.setLineWrap(true);   
        test.setWrapStyleWord(true);
        test.setEditable(false);  


        JScrollPane spane = new JScrollPane(test);
        spane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        GridBagLayout gbl = new GridBagLayout(); 
        gbl.setConstraints(spane,k);     
        JPanel panel = new JPanel(gbl);
        panel.add(spane);  
        add(panel);     

    }
    public static void writetext(){

        test.setText("I have a message ");


    }

   }   

In this situation I want to write some thing I use the writetext method. I want to write in this place from another class.

that is as follows


package control;



import generated.IMaritimeRadarControlCommand;

import generated.IMaritimeRadarControlState;
import generated.IMaritimeRadarTrackUpdates;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import org.apache.log4j.Logger;


import view.LabelStatus;




public class CommandSubscriber implements MessageListener {
    IMaritimeRadarControlCommand mradarcontrolcommand;
  /**
     * Logger
     */
    private static final Logger logger = Logger.getLogger(CommandSubscriber.class);

    private PluginTester plugin;




    public CommandSubscriber(final PluginTester plugin) {
        this.plugin = plugin;



    }


    /**
     * Overwritten method.
     * Called from JMS to handle control command.
     * @param message Received message
     */
    @Override
    public final void onMessage(final Message message) {



        logger.info("entering onMessage()");
            if (message instanceof TextMessage) {
                TextMessage textMsg = (TextMessage) message;

                String type = null;
                try {
                  type = textMsg.getStringProperty("TYPE");
                } catch (JMSException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                String xml = null;
                try {
                    xml = textMsg.getText();
                } catch (JMSException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                logger.info("received message: '" + xml);

                if (type.equals("MaritimeRadarControlCommand")) {
                    mradarcontrolcommand=ControlCommandFactory.unMarshalling(xml,this.getPlugin());
                    System.out.println("\n SENDING THE MESSAGE TO LABEL STATUS");

                    LabelStatus.writetext();

                }
                else {
                    logger.warn("Unknown TextMessage received. type: " + type);
                }
            }
     }
    /**
     * 
     * @return PluginTester for xml schema for jaxb unmarshalling
     */
    public final PluginTester getPlugin() {
        return plugin;
    }
    //  logger.info("leaving onMessage()");
}

You can see

that in the onMessage method I call the writetext method of the labelStatus class. But it does not work. Let me know how to work with it.

Edited 4 Years Ago by Ezzaral: Code formatting. Please read "Formatting Help"(http://www.daniweb.com/community/syntax) to learn about formatting.

hello Norm R1 the problem is it does not do anything. it suppose to write that string on the text field.There is no error message, it seems like that it is just not there I mean LabelStatus.writetext() just does not execute. If I print it on the System out it works.

LabelStatus.writetext();

Can you make a testing program without the third party packages the compiles, executes and shows the problem?

This question has already been answered. Start a new discussion instead.