Hello I'm trying to get a jTextField to be updated by another class however the validate() and repaint() aren't working. However, it is saying that the text has been changed for my jTextField. Below is the code could anybody explain to me why its not updating the repainting the jTextField to show the text change?

Thanks, Viking3579

package songbirdvoicecontrolgui;

import java.io.*;
import java.lang.*;

public class voicecontrolgui extends javax.swing.JFrame {

    /** Creates new form voicecontrolgui */
    public voicecontrolgui() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     */
    private void initComponents() {

        jPanel = new javax.swing.JPanel();
        RecognitionResultjTextField = new javax.swing.JTextField();
        RecognitonResultjLabel = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        AlternativesjList = new javax.swing.JList();
        AlternativeRecognitonjLabel = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Songbird Voice Control");
        setBackground(new java.awt.Color(54, 52, 63));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setFont(new java.awt.Font("Times New Roman", 0, 12)); // NOI18N
        setName("SongbirdVoiceControlFrame"); // NOI18N

        jPanel.setBackground(new java.awt.Color(54, 52, 63));
        jPanel.setPreferredSize(new java.awt.Dimension(600, 200));

        RecognitionResultjTextField.setBackground(new java.awt.Color(94, 92, 101));
        RecognitionResultjTextField.setEditable(false);
        RecognitionResultjTextField.setFont(new java.awt.Font("Times New Roman", 0, 12)); // NOI18N
        RecognitionResultjTextField.setForeground(new java.awt.Color(163, 210, 197));
        RecognitionResultjTextField.setText(" Listening ...");
        RecognitionResultjTextField.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        RecognitonResultjLabel.setBackground(new java.awt.Color(0, 0, 0));
        RecognitonResultjLabel.setFont(new java.awt.Font("Times New Roman", 0, 12)); // NOI18N
        RecognitonResultjLabel.setForeground(new java.awt.Color(163, 210, 197));
        RecognitonResultjLabel.setText("Voice Recognition:");

        jScrollPane1.setBackground(new java.awt.Color(94, 92, 101));
        jScrollPane1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        AlternativesjList.setBackground(new java.awt.Color(94, 92, 101));
        AlternativesjList.setForeground(new java.awt.Color(163, 210, 197));
        AlternativesjList.setModel(new javax.swing.AbstractListModel() {

            String[] strings = {"No Alternatives Found"};

            public int getSize() {
                return strings.length;
            }

            public Object getElementAt(int i) {
                return strings[i];
            }
        });
        jScrollPane1.setViewportView(AlternativesjList);

        AlternativeRecognitonjLabel.setBackground(new java.awt.Color(0, 0, 0));
        AlternativeRecognitonjLabel.setFont(new java.awt.Font("Times New Roman", 0, 12));
        AlternativeRecognitonjLabel.setForeground(new java.awt.Color(163, 210, 197));
        AlternativeRecognitonjLabel.setText("Voice Recognition Alternatives:");

        //jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/songbirdvoicecontrolgui/songbird.jpg")));

        javax.swing.GroupLayout jPanelLayout = new javax.swing.GroupLayout(jPanel);
        jPanel.setLayout(jPanelLayout);
        jPanelLayout.setHorizontalGroup(
                jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanelLayout.createSequentialGroup().addContainerGap().addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(RecognitonResultjLabel).addComponent(RecognitionResultjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE).addGroup(jPanelLayout.createSequentialGroup().addGap(10, 10, 10).addComponent(jLabel1))).addGap(10, 10, 10).addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE).addComponent(AlternativeRecognitonjLabel)).addContainerGap()));
        jPanelLayout.setVerticalGroup(
                jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanelLayout.createSequentialGroup().addContainerGap().addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(RecognitonResultjLabel).addComponent(AlternativeRecognitonjLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanelLayout.createSequentialGroup().addComponent(RecognitionResultjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jLabel1)).addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)).addContainerGap()));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 425, Short.MAX_VALUE));
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE));

        pack();
    }

    public void setRecognitionResultjTextField(String s) {
        RecognitionResultjTextField.setText(s);
        RecognitionResultjTextField.validate();
        RecognitionResultjTextField.repaint();
    }

    public String getRecognitionResultjTextField() {
        String s = RecognitionResultjTextField.getText().toString();
        return s;
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new voicecontrolgui().setVisible(true);
            }
        });
        //songbirdvoicecontrol.Voicecontrol.main(args);
        modifygui mod = new modifygui();
        mod.modifygui();
    }
    // Variables declaration
    private javax.swing.JLabel AlternativeRecognitonjLabel;
    private javax.swing.JList AlternativesjList;
    public javax.swing.JTextField RecognitionResultjTextField;
    private javax.swing.JLabel RecognitonResultjLabel;
    private javax.swing.JLabel jLabel1;
    public javax.swing.JPanel jPanel;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration
}
package songbirdvoicecontrolgui;

public class modifygui {

    public void modifygui() {
        voicecontrolgui voicecontrolgui = new voicecontrolgui();
        System.out.println("RecognitionResultjTextField: " + voicecontrolgui.getRecognitionResultjTextField());
        System.out.println("voicecontrolgui.RecognitionResultjTextField.setText( \"Still Listening...\");");
        voicecontrolgui.setRecognitionResultjTextField(" Still Listening...");
        System.out.println("RecognitionResultjTextField: " + voicecontrolgui.getRecognitionResultjTextField());
    }
}

so much netbeans code...

anyway, you use repaint() and validate(). While you use the re-paint, why not use re-validate?

This article has been dead for over six months. Start a new discussion instead.