• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Why the result of printing a JFrame is different from what I'm viewing on screen?  RSS feed

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to print a JFrame and text looks different from what I see on screen. All graphics looks good and exactly as it is displayed but the text looks different, especially the spacing of the characters.
I tried different codes I found on the web but basically all of them uses the print method.
The problem is not related to the printer (a real one or a PDF one), the result is always different from what I see onscreen.
I searched on the web but no one seem to have the same issue. I tried different fonts and none of them worked but I noticed that the problem is more evident if font size is bigger.
Thanks in advance for you help.
 
Saloon Keeper
Posts: 9255
177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

What do you mean by "trying to print a JFrame"? Can you show us the code you've used?
 
Luca Vanon
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.
I could show you several codes I tried, but let's be fast and see the easy one:


To make you understand the problem, see the attachments.
It seems that rendering text to the printer cause spacing problems...

Video.png
[Thumbnail for Video.png]
What I see on video
Printer.png
[Thumbnail for Printer.png]
What I get from printer
 
Stephan van Hulst
Saloon Keeper
Posts: 9255
177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry, but I don't know what PrintUtillitiesLandscape is. Is it from a third party library or did you write it yourself?
 
Luca Vanon
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I thought that was a standard... I'm working on this software since years, I onestly forgot where I got all the pieces...
By the way, let's get another one, the result is the same:


And to call it:


Apart from that, what method should I use to simply print a Jpanel to a printer without all these problems?
 
Luca Vanon
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is another simple implementation, same result...



Same problem, the printed texts are simply wrong, the spacing between the words and the letters.
 
Luca Vanon
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If someone is there and would like to help me, I can show you what is happening...

This is what I see on video:

And this is what I get on the printer (real or PDF, same result):


Am I the only one to face this problem?
 
Master Rancher
Posts: 3276
33
 
Stephan van Hulst
Saloon Keeper
Posts: 9255
177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you first create a full SSCCE for us so we may replicate the issue?
 
Luca Vanon
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did a small example to replicate my very complex and long software and it's bug.
I tried also to remove the windows look and feel but it doesn't help much.

 
Luca Vanon
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to be complete, I have tried to compile with different versions (1.6/1.7/1.8) because I have read on the internet that there is a similar bug in 1.6, but unfortunately it didn't help.
Another thing: in the code I posted above there is an incomplete html code in one of the two components, but it's not the problem.
Using plain text or html code makes no difference anyway.
 
Luca Vanon
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could someone give me a simple example on how could I use javax.print instead of java.awt.print?
I'm searching the web for a tutorial, but didn't find it yet.
Maybe this could help to solve the issue ...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!