[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Java programming

Posted on 2013-11-11
3
Medium Priority
?
437 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 2000 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

This is about my first experience with programming Arduino.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to implement Singleton Design Pattern in Java.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

650 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