0

javax.swing.text.DefaultStyledDocument으로 확장되는 클래스에 간헐적 인 문제가 발생합니다. 이 문서는 프린터로 전송됩니다. 대부분의 경우 문서의 형식이 올바른 것처럼 보이지만 잠시 후에는 그렇지 않습니다. 서식의 일부 변경 사항이 적용되지 않은 것 같습니다. DefaultStyledDocument.styleChanged (스타일 스타일)가 적시에 실행되지 않을 수 있습니까?

은 내가 DefaultStyledDocument.styleChanged(Style style) 코드를 살펴했다 :

/** 
* Called when any of this document's styles have changed. 
* Subclasses may wish to be intelligent about what gets damaged. 
* 
* @param style The Style that has changed. 
*/ 
protected void styleChanged(Style style) { 
    // Only propagate change updated if have content 
    if (getLength() != 0) { 
     // lazily create a ChangeUpdateRunnable 
     if (updateRunnable == null) { 
      updateRunnable = new ChangeUpdateRunnable(); 
     } 

     // We may get a whole batch of these at once, so only 
     // queue the runnable if it is not already pending 
     synchronized(updateRunnable) { 
      if (!updateRunnable.isPending) { 
       SwingUtilities.invokeLater(updateRunnable); 
       updateRunnable.isPending = true; 
      } 
     } 
    } 
} 

/** 
* When run this creates a change event for the complete document 
* and fires it. 
*/ 
class ChangeUpdateRunnable implements Runnable { 
    boolean isPending = false; 

public void run() { 
     synchronized(this) { 
      isPending = false; 
     } 

    try { 
    writeLock(); 
    DefaultDocumentEvent dde = new DefaultDocumentEvent(0, 
         getLength(), 
         DocumentEvent.EventType.CHANGE); 
    dde.end(); 
    fireChangedUpdate(dde); 
    } finally { 
    writeUnlock(); 
    } 
} 
} 

SwingUtilities.invokeLater(updateRunnable)이 내가되기 전에 문서에 나타나는 내 서식 변경 믿을 수 없다는 의미가 아니라 invokeAndWait(updateRunnable)보다,라고 사실을합니까 렌더링?

업데이트가 발생할 때까지 렌더링을 계속하지 않도록하는 방법이 있습니까?

답변

2

코드 끝에 fireChangedUpdate(dde);이 표시됩니다. DocumentListener으로 자신을 추가하십시오. DocumentListener.changedUpdate 메서드 내에서 모든 변경 내용을 포함하여 문서를 인쇄하려면 저장해야합니다.

1

비슷한 문제가 있습니다.

resolv하려면 스윙 텍스트, 비어있는 invokeLater로 설정 한 다음이 invokeLater가 완료되면 나중에 호출되는 스윙 텍스트가 수행되기를 바랍니다.

doc.formatSomethingWhichPerhapsLaunchInvokeLater(); 
EventQueue.invokeLater(new java.lang.Runnable() 
{ 
    public void run() 
    { 
    // at this point, I hope all swing text stuff is finish. 
    // Until now, it's the case. 
    } 
}); 

그것은 horribel하지만 그것은 죄송합니다, 작업입니다 :

내 코드 내 영어가 아닌 아마 더 낫다.