列印出JTextComponent的文字內容, 並進行分頁後預覽
Sergey Groznyh’s Blog: Swing Archives
Generating Print Preview of Swing Text Components
Posted by g_s_m on September 05, 2007 at 04:42 AM | Permalink | Comments (6)This question, “how to generate print preview of Java Swing components,” is asked often on various discussion forums, because currently (as of version 6) the Java SE doesn’t have standard facilities for building print previews. While working on the Swing Tutorial, I tried to address this issue under the topic “Using JTextComponent.getPrintable method.” This will hopefully appear in the updated version of the Swing Tutorial for JDK6. In the meantime, I’ll put the relevant information here.
There exist several resources on the Internet related to generating print previews in Java, but in most cases they are either commercial, or use an outdated API, or attempt to build some all-in-one custom dialog solution without paying much attention to details. In this issue I’ll try to focus on how to create a print preview—what necessary parts are involved and how they do communicate.