Solved

Java programming

Posted on 2013-11-11
3
421 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 36

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 36

Expert Comment

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

717 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