views:

64

answers:

2

I cant seem to get this statement to work during run time.

textWords.setText(item);

textWords is an object, setText is a method and item is an integer.

Anyone familiar with this? I cannot seem to get this to work during runtime.

There is no error, during runtime it just doesn't do anything!

public class frmMain extends javax.swing.JFrame { public frmMain() { initComponents(); textWords.append("Bryan"); // THIS works!! but this only //happens when the form is initialized, not very usefull } //Other pre generated code here.

private void displayItem() { //Method I created to help me catch data // and make a call to this form. // none of these are working. txtTest.setText(item);

    textWords.setText(item);
    textWords.insert("Bryan",1);
    textWords.append("number");
}
A: 

I'm guessing that what you need is:

textWords.setText(Integer.toString(item));

i.e. you need to convert the 'item' (an integer) to a String. You can do this in a different way thus:

textWords.setText("" + item);
Brian Agnew
A: 

Are you sure you are making the changes on the EDT? Changing GUI components on any other thread may produce undefined results.

Try adding this code at the beginning of displayItem():

 if (!SwingUtilities.isEventDispatchThread()) {
     SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            displayItem();
        }
    });
    return;
 }

If the call to displayItem is not on the EDT, it creates a runnable and redispatches it on the EDT.

See also http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html

Devon_C_Miller