开发者

Using Java Controls/Properties during runtime?

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
开发者_StackOverflow}
 //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");
}


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);


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜