2016-10-16 1 views
1

Java JDK 1.6을 사용하고 있으며 JTextPane을 사용하여 고정 폭 글꼴로 텍스트를 표시하는 데 문제가 있습니다. 같은 UTF8 문자를 추가하자마자, 텍스트 판의 줄 높이가 줄어 듭니다 (이미 창에있는 모든 텍스트와 나중에 추가 된 모든 텍스트에 대해). 어떻게 이것을 피할 수 있습니까? 나는 정상적인 선 높이를 갖고 싶다.Java JTextPane은 UTF8 문자가 추가 될 때 줄 높이를 변경합니다.

class AttributedTextPane extends JTextPane 
    { 

     private DefaultStyledDocument defaultStyledDocument; 

     protected AttributedTextPane() 
     { 
      this.defaultStyledDocument = new DefaultStyledDocument(); 
      this.setDocument(defaultStyledDocument); 

      this.setContentType("text/plain"); 
      ... 
     } 
    } 
    ... 

이 창은 JInternalFrame의에 통합되어 있습니다 : 여기

은 몇 가지 예제 코드입니다. 패널 만들기 및 고정 폭 글꼴 설정 :

Font font = new Font("DejaVu Sans Mono", Font.PLAIN, 11); 
    AttributedTextPane pane = new AttributedTextPane(); 
    pane.setFont(font); 

원하는 텍스트를 표시하려면 pane.setText (...); UTF8 문자를 추가하자마자 선 높이가 변경됩니다. 화면 캡처는 http://i.imgur.com/Fq7XBJB.png입니다. 선 높이가 변경되는 것을 피할 수있는 방법이 있습니까? 감사합니다, 디제이

답변

0
+0

감사합니다,하지만 사용 :

MutableAttributeSet jTextPaneSet = new SimpleAttributeSet(pane.getParagraphAttributes()); StyleConstants.setLineSpacing(jTextPaneSet, 1.5f); //replace float 1.5f with your desired line spacing/height 

소스 .setLineSpacing (...) 도움이되지 않는 것 같습니다. 나는 그것을 테스트했지만 아무것도 바뀌지 않았다. 다른 스타일 매개 변수 (예 : 색, 굵게, 기울임 꼴)를 변경하면 잘 작동하지만 줄 간격은 없습니다. – Deejay

+1

죄송합니다, 마지막 코멘트를 수정해야합니다. 이미 늦은 것 같아서 실수를 저질렀습니다. StyleConstants.setLineSpacing (...)을 사용하면 새로운 속성을 패널에 설정하는 것을 놓치지 않으셔도됩니다. 'MutableAttributeSet jTextPaneSet = new SimpleAttributeSet (pane.getParagraphAttributes()); StyleConstants.setLineSpacing (jTextPaneSet, 0.2f); pane.setParagraphAttributes (jTextPaneSet, true); ' 감사합니다. – Deejay

관련 문제