[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

printing problem very urgent

Posted on 2004-11-10
9
Medium Priority
?
196 Views
Last Modified: 2010-03-31
hi,

i have the following code to print:

private void Print() {
        Frame f = new Frame( "Printing" );
        f.pack();
        PrintJob pj = f.getToolkit().getPrintJob( f, "Printing Results", null );
        if ( pj != null ) {
            g = pj.getGraphics();
            fnt = new Font( "Trebuchet MS", Font.PLAIN, 14 );
            g.setFont(fnt);
            g.drawString(textareaEng.getText() + "\n\n" + textareaFre.getText() + "\n\n" + textareaSol.getText(), 30, 30 );
            g.dispose();
            pj.end();
        }
    }

but the problem is when its printed, i get small squares where there should be a new line!

if i was to use JDK1.5 which im currently using for writing program everything works perfect cos i use replaceAll(), but my client is running JDK1.3 and replaceAll only works for JDK1.4 and higher. (to my knowledge)

i need to be able to overcome this and print newlines where "\n" is instead of squares...

so say

textareaEng = "hello world";
textareafre = "bonjour monde";
textareaSol = "sosol lf";

using my code above would print

hello world □□ bonjour monde □□ sosol lf

but i want it to print out so it looks like :

hello world

bonjour monde

sosol lf

this is very urgent

thanks sean
0
Comment
Question by:ellandrd
  • 5
  • 4
9 Comments
 
LVL 16

Author Comment

by:ellandrd
ID: 12544698
sorry i used the character map to show small squares but □□ showed up instead  - sorry

hope you stillunderstand by what i mean from above?!
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12544703
Does

            g.drawString(textareaEng.getText() + "\n\r\n\r" + textareaFre.getText() + "\n\r\n\r" + textareaSol.getText(), 30, 30 );

help?

(or  "\r\n\r\n")
0
 
LVL 16

Author Comment

by:ellandrd
ID: 12544714
i tried \r\n and it didnt work but will try \n\r so please wait a minute till i update my code...
0
Technology Partners: 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!

 
LVL 16

Author Comment

by:ellandrd
ID: 12544727
nope it didnt work!
0
 
LVL 37

Accepted Solution

by:
zzynx earned 2000 total points
ID: 12544737
Eventually you can split

            g.drawString(textareaEng.getText() + "\n\n" + textareaFre.getText() + "\n\n" + textareaSol.getText(), 30, 30 );

into

int y = 30;
g.drawString(textareaEng.getText(), 30, y);
y+=40; // 40 or another number
g.drawString(textareaFre.getText(), 30, y);
y+=40;
g.drawString(textareaSol.getText(), 30, y);


can't you?
0
 
LVL 16

Author Comment

by:ellandrd
ID: 12544763
jeez never tried that!

havent got my java head on....

will be right back
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12544765
Should work I think
0
 
LVL 16

Author Comment

by:ellandrd
ID: 12544794
yes it worked!

thank you for the fast reply adn working answer!

500 points and grade A

cheers sean
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12544802
:°))
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month20 days, 2 hours left to enroll

873 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