Solved

Java programming

Posted on 2013-11-11
3
404 Views
Last Modified: 2013-11-11
I am using the following code to print a string to my prnter.  It appears as though the font is proportional and makes it impossible to keep columns straight.  How would I set the font to something like times Roman so I can set up a formatted string that will not be all over the place

                JTextPane textPane = new JTextPane();

                textPane.setText(printString);
                try {    
                    textPane.print();
0
Comment
Question by:sargent240
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 39640750
After creating your JTextPane you just need to set the "font" on it. Add the following line just after you call the constructor...
textPane.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

Open in new window

By the way, Times Roman is NOT a fixed-width font, you would still get the same issues. In the above, feel free to replace the use of the Font.MONOSPACED constant with an actual font name if you want to tweak it further. Fonts like "Courier New" are the fixed-width fonts that you would be after. Using the constant however, should be more portable across different systems, although I doubt you could find a computer/os that doesn't have Courier New available!

Obviously, you can also play with the point size and style specified in the line above to further change the desired output.
0
 

Author Closing Comment

by:sargent240
ID: 39640772
Thank you very much for your help. and the added explanation.
0
 
LVL 35

Expert Comment

by:mccarl
ID: 39640774
Not a problem! :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
allswap challenge 6 75
Checkbox and ListView in Android Layout 4 56
Groovy problem when using SOAPUI : DispatchException occurred 7 27
java jdbc batch example 8 17
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now