2014-12-08 1 views
0

그래서 배열이 있습니다. 내 현재 코드는 지금을 보여스윙의 객체 배열

는이

public void setLblEvents(Calendar[] calendars) { 

     String result = ""; 
for(int i = 0; i< calendars.length; i++) 
{ 
    result += (+i +calendars[i].getTitle()); 
    result += (+i +calendars[i].getStartDate()); 
    result += (+i +calendars[i].getEndDate()); 
    result += (+i +calendars[i].getNote()); 
    result += (+i +calendars[i].getLocation()); 
} 

lblEvents.setText(result); 

} 

이 내 JLabel의 텍스트의 1 개 라인, 등등 모든 제목, 모든 startdates를 출력처럼 보이는 JLabel의입니다.

어떻게 이런 방식을 가장 간단한 방법으로 표시 할 수 있습니까?

+0

추가해야? – csmckelvey

+1

점잖은 렌더러와 함께'JList'를 사용합니까? HTML을 사용 하시겠습니까? 나중에 그걸로하고 싶은 것에 조금 달려있다. – Robin

+1

나는'JTable'을 사용할 것이다. 자세한 내용과 예제는 [테이블 사용 방법] (http://docs.oracle.com/javase/tutorial/uiswing/components/table.html)의 스윙 튜토리얼을 참조하십시오. – camickr

답변

0

여러 줄의 라벨에 텍스트를 표시하려면 "\ n"`당신은 어디에서 줄 바꿈을하려면`, 다음과 같은 것을 할

String result = "<html>"; 
for(int i = 0; i< calendars.length; i++){ 
    result += (+i +calendars[i].getTitle()+"<br>"); 
    result += (+i +calendars[i].getStartDate()+"<br>"); 
    result += (+i +calendars[i].getEndDate()+"<br>"); 
    result += (+i +calendars[i].getNote()+"<br>"); 
    result += (+i +calendars[i].getLocation()); 
} 

result += "</html>" 

lblEvents.setText(result);