2009-11-26 3 views
0

런타임 동안이 명령문이 작동하지 않는 것 같습니다.런타임 동안 Java 컨트롤/속성 사용?

textWords.setText(item);

textWords 개체이다의 setText는 방법 및 제품의 정수이다.

누구나 익숙한가요? 런타임 중에이 작업을 수행 할 수없는 것 같습니다.

런타임 중에 오류가 없습니다. 아무 것도하지 않습니다.

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"); 
} 
+2

후 더 많은 코드, 오류, 이것보다 더 아무것도 참조하십시오. 당신의 질문에서 어떤 것을 말할 수 없습니다. – duffymo

답변

0

내가 무엇을 당신이 필요로하는 것은 같은데요 :

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

즉 당신이 문자열에 '항목'(정수)를 변환해야합니다. 다음과 같이 다른 방법으로이 작업을 수행 할 수 있습니다.

textWords.setText("" + item); 
0

EDT를 변경 하시겠습니까? 다른 스레드에서 GUI 구성 요소를 변경하면 정의되지 않은 결과가 발생할 수 있습니다. displayItem()의 시작 부분에이 코드를 추가

시도 : displayItem에 대한 호출이 EDT에없는 경우

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

, 그것은 실행 가능한를 생성하고 EDT에 그것을 재발송합니다.

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

관련 문제