Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7039303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:46:55+00:00 2026-05-28T01:46:55+00:00

Let me first describe the picture below: There are two printed papers. The only

  • 0

Let me first describe the picture below:

  • There are two printed papers. The only difference between them is that few space ” ” characters from paper in left are replaced by dot “.” character in the paper in right.
  • Red line represents the left border to which the text should be aligned
  • Green curve represents my intention to align all characters it connects into a single column. In fact the green curve is supposed to be a vertical line.

enter image description here

I want all characters highlighted by the green line to be printed in one column.

Font of a String is monospaced Courier New. However, it seems that space characters are not printed as monospaced (see ‘dotted’ lines vs. lines with space characters at the beginning).

To print the string I use standard Java Print Service API over JTextPane component:

PrinterJob pj = PrinterJob.getPrinterJob(); 
pj.setPrintable(myTextPane);
pj.print();

To my knowledge the Java Print Service API in fact calls paint() methods of myTextPane.
Therefore the preview should look exactly the same as the printed version of String.

However, it doesn’t. The preview does not seem to misinterpret monospaced space characters (see the last picture). The preview looks exactly as I want the text to be printed.

enter image description here

Any suggestions how to force JavaPrintServiceAPI to print monospaced space characters correctly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:46:56+00:00Added an answer on May 28, 2026 at 1:46 am

    I don’t think you can fix this in the printing API.

    First divide each line after the “green” digit into a left and (possibly empty) right substring.

    In your JTextArea, use align to justify a two-column HTML table, as described in How to Use HTML in Swing Components.

    As an alternative to JTextPane, use a GridLayout of JLabel. Give the left column RIGHT_ALIGNMENT and the right column LEFT_ALIGNMENT.

    A two-column JTable, which uses JLabel for rendering, might be a third alternative. See How to Use Tables—Concepts: Editors and Renderers for details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me first describe the problem. I have this application that opens a word
Let me first describe my goal: I have created an object with 3 properties:
I've got a strange problem. Let me first describe my situation: Webserver01 (Webapplication, SQL,
Thanks for viewing my question. Let me describe the app first. I have a
First let me say that I really feel directionless on this question. I am
First let me state that, despite being a fairly new practitioner of TDD, I'm
First let me say that I did see this article: How to remove AspxAutoDetectCookieSupport
Let me first describe the situation. We host many Alumni events over the course
Let me first describe the situation the best I can. So I am working
First off, I don't know if this is possible, but let me describe my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.