2012-01-31 4 views
1

나는 Java를 처음 사용하여 SWT StyledText 상자에 추가 할 다음 텍스트에 사용할 글꼴 및 글꼴 색을 설정하는 방법을 알고 싶습니다.Java StyledText, 다른 글꼴로 텍스트를 추가 하시겠습니까?

예를 들어 "명령"및 "데이터"텍스트를 정의하는 응용 프로그램이 있고 각기 다른 글꼴/색으로 표시되어야합니다. 이제 "명령"텍스트를 추가했다고 가정 해 봅시다. 이제 "데이터"텍스트가 될 다음 텍스트가 다른 글꼴과 색상으로 표시되도록 어떻게 설정합니까?

나는 인터넷 검색을 많이 해왔지만 아무 것도 나를 도와주지 못하는 것 같습니다.

PS :이 수 없습니다 그것을 할 수있는 가장 효율적인 방법 : 그래서 모든 나는 작업을 수행하는 다음과 같은 방법을 마련 할 수있었습니다

int a = st.getCharCount(); 

Font font = new Font(shlProtruleModifier.getDisplay(), "Courier", 10, SWT.NORMAL); 

StyleRange[] sr = new StyleRange[1]; 

sr[0] = new StyleRange(); 

st.append("\r\nWhat the heck?"); 

sr[0].start = a; 
sr[0].length = st.getCharCount() - a; 
sr[0].font = font; 
sr[0].foreground = SWTResourceManager.getColor(SWT.COLOR_BLACK); 

st.replaceStyleRanges(sr[0].start, sr[0].length, sr); 
+1

이것은 그것을하는 방법입니다 :-) –

답변

1

,

int a = st.getCharCount(); 

Font font = new Font(shlProtruleModifier.getDisplay(), "Courier", 10, SWT.NORMAL); 

StyleRange[] sr = new StyleRange[1]; 

sr[0] = new StyleRange(); 

st.append("\r\nWhat the heck?"); 

sr[0].start = a; 
sr[0].length = st.getCharCount() - a; 
sr[0].font = font; 
sr[0].foreground = SWTResourceManager.getColor(SWT.COLOR_BLACK); 

st.replaceStyleRanges(sr[0].start, sr[0].length, sr); 
관련 문제