
July 5th, 2004, 01:11 PM
|
|
Registered User
|
|
Join Date: Jul 2004
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Printing a text file
I'm trying to print a page of formatted text, but I'm finding to java.awt.print to be extremely difficult to use. I tried that javax.print and it was great, but isn't implemented fully on the Mac yet, and I can't worry about the platform for this project. Is there a simple way to just create a text file, and have java.awt.print, print it? If not, I have a few questions about what I've got so far. I'm trying to print some highlighted fields like name. I want the Field title to be in bold, and the value to be just after it in a regular font, but I can't seem to get two different fonts on the same line with the correct horizontal placement. I just don't know how to find the end of the line. I'm placing the text in an invisible JTextArea, and pulling each line off at a time with
try {
lineStart = textarea.getLineStartOffset(lineNumber);
lineEnd = textarea.getLineEndOffset(lineNumber);
strText = textarea.getText(lineStart, lineEnd-lineStart);
}
The getLineEndOffset, seems to work here, but if I try graphics.drawString with a starting position of getLineEndOffset it's way off. I realize that drawString is part of graphics and getlineEndOffset is part of JTextComponent so I shouldn't expect the values to match up, but I don't have any other ideas.
-Ryan
|