Solved

Java programming

Posted on 2013-11-11
3
412 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AutoIncrement column based of FK 11 64
Programming Codes 2 42
jsp error 6 46
Where to download python requests library 6 64
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

733 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