Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2007

Tip: Looking for answers? Try searching our database.

How to print a JTextArea?

Thread view: 
layne79 - 20 Mar 2007 17:51 GMT
Hello,
I'm trying to implement a printing mechanism for JTextArea but I have
a problem on extracting lines from it.
I used the xample found at http://java.sun.com/docs/books/tutorial/2d/printing/set.html
(PaginationExample class) but, instead of having available an array of
String (textlines), I have a JTextArea.
I need to replace the instruction

g.drawString(textLines[line], 0, y);

at line 93

with another, taking lines from the textarea.

Dou you know how I can do that?
Dan Andrews - 21 Mar 2007 02:07 GMT
> Hello,
> I'm trying to implement a printing mechanism for JTextArea but I have
[quoted text clipped - 11 lines]
>
> Dou you know how I can do that?

Layne,

Ever since JDK1.6 the JTextArea has a method called getPrintable that
it gets from JTextComponent. You could start there instead of writing
your own printable.

Cheers,
Dan Andrews
---------------------------
http://www.ansir.ca
layne79 - 21 Mar 2007 10:53 GMT
Dan Andrews ha scritto:

> > Hello,
> > I'm trying to implement a printing mechanism for JTextArea but I have
[quoted text clipped - 17 lines]
> it gets from JTextComponent. You could start there instead of writing
> your own printable.

Sorry but I can't use JDK 1.6
May you suggest an alternative?
Thank you and bye.
Dan Andrews - 21 Mar 2007 18:54 GMT
> Sorry but I can't use JDK 1.6
> May you suggest an alternative?
> Thank you and bye.- Hide quoted text -

Personally, I'd likely implement a Printable that used the text area's
paint component method. The drawback is that you would need to
calculate the page breaks. There are lots of examples on the internet.
Here is a link to one solution that you can get to by a google for the
terms Printable JTextArea.

http://forum.java.sun.com/thread.jspa?forumID=57&threadID=212065

Cheers,
Dan Andrews
---------------------------
http://www.ansir.ca
Brandon McCombs - 22 Mar 2007 03:54 GMT
>> Hello,
>> I'm trying to implement a printing mechanism for JTextArea but I have
[quoted text clipped - 15 lines]
>
> Ever since JDK1.6 the JTextArea has a method called getPrintable that

Ever since? You say that like 1.6 has been out for ages when in fact
it's the latest version available and only came out within the last few
months.

> it gets from JTextComponent. You could start there instead of writing
> your own printable.
[quoted text clipped - 3 lines]
> ---------------------------
> http://www.ansir.ca


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.