-1

OK, So i finally figured out how to print a JTextPane, and really have a fully functioning document editor.

Anyway, Can I make the JTextPane the size of a piece of paper (with page breaks) So you can easily predict the appearance of the document you are typing? Any tips/hints would be helpful!

edit: format of the JTextPane is 'text/rtf', if that helps.

David Kroukamp
  • 36,155
  • 13
  • 81
  • 138
Primm
  • 1,347
  • 4
  • 19
  • 32

3 Answers3

2

May be the links could help

http://java-sl.com/Pagination_In_JEditorPane.html

http://java-sl.com/Pagination_In_JEditorPane_Print.html

StanislavL
  • 56,971
  • 9
  • 68
  • 98
1

The Printable returned by the getPrintable() method of JTextComponent "formats the document content appropriately for the page size." If this is insufficient, please edit your question to include an sscce that exhibits the problem you're having.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I see how it prints it fine, but how can i make the JTextPane appear as documents do in Word, like pieces of paper, and the right size? – Primm Jul 08 '12 at 20:11
  • I usually rely on the host platform's preview capabilities, but you could interrogate existing [*Print Services and Attributes*](http://docs.oracle.com/javase/tutorial/2d/printing/services.html). – trashgod Jul 08 '12 at 20:19
0

I would suggest using a layout manager

How can I create a JTextArea with a specified width and the smallest possible height required to display all the text?

As for setting the width, you'll want to calculate it based on the page format specified. It could be 8.5x11 or in landscape or a completely different size altogether.

pageFormat.getImageableWidth();
pageFormat.getImageableHeight();
Community
  • 1
  • 1
Paul Way
  • 1,966
  • 1
  • 13
  • 10