Let me begin by saying, before I digress into stream-of-consciousness blogging mode, that I've got a solution to some tricky Java printing problems. The bottom of this post contains code that you can re-use, for free, to very easily print the multi-page contents of Java Swing components.
In many ways, Java makes an excellent language for developing desktop GUI applications. The Swing toolkit is rich and versital and makes performing certain kinds of tasks relatively easy. (For example, mouse scroll button support is "automagic" in all JScrollPanes, and the default implementation--whatever you mouse over you scroll--is a feature I wish other platforms would embrace.)
But, of course, its limitation are legion, and it is certainly not your first choice when your goal is to develop a desktop GUI app rapidly.
In a previous post I mocked WebObjects for it's amaturish Java GUI. But anyone who has ever used Eclipse knows that Java can build rich, clean, and rock-solid visual applications. (Yes, I know, Eclipse does not use Swing, but that's another story.) And dare I toot my own horn (Nilges does it all the time, so why not?) and mention that the aspect of SourceJammer (the version control application I developed) that users typically say they like most is the clean and easy-to-use GUI. So we know it's possible to GUI development right with Java.
But out of the box, Swing has some serious limitation that make the learning curve steep and development slow and treacherous. One glaring problem is the lack of a standard combo box component with typeahead support. If you want typehead in your combobox in a Swing app, you have to either a) figure out how to implement this yourself, b) pay money for some 3rd-party toolkit or c) trust in one of the very few open source solutions (PSwing at http://pswing.sourceforge.net/, which I also developed, being one).
Another glaring shortcoming of the Swing api is very poor support for printing.
Well, let me rephrase that. The support is excellent and highly configurable. It's just incredibly difficult to use.
For the past several days I was tasked with figuring out how to perform batch printing from a Swing application. More specifically, the application needed to hit a series of web pages and print each page--not the raw HTML, of course, but the generated page. This was far more difficult than it should have been.
The Swing JEditorPane provides reasonable rendering of web pages. Don't expect it to work if you've got frames or javascript, though. Low tech pages only, please. Regardless, that part was easy enough to get up and running.
It was the printing tha really gave me fits.
Explanations of how to print using Swing are few and far between on the internet. One of the better ones was located here.
In order to print the contents of a Swing component, you first need to create an Object that implements the Printable interface. There is no default implementation of Printable out there in Javaland that I could find. Nope. You've got to build your own, and this means implementing the print() method which needs to deal with the underlying Graphics object (arrggg!) and also figuring out which portion of the component to print based on the page number.
I must be kidding or simply mis-informed, right? Surely it can't be that complex? Graphics math? Apple II-e, anyone? Sadly, Sun's assumption seems to be that, yes, developers should implement the print() method themselves. See their tutorial on the subject here.
Luckily, I discovered a some code on a forum at java.sun.com that made this process a little bit easier. I combined the code posted on that forum with the code from the tutorial above (not the Sun tutorial, the one from http://www.ap1.jhu.edu/). In the public interest, I post the combination here in the hope that this will be helpful to someone some day.
The following code can be compiled into a class that can easily print the multi-page contents of a Swing component. If fact, if you just use the static print() method, you're user will see the print dialog and everything else will happen without you having to get your fingers dirty.
/*
* Copied from this tutorial:
*
* http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-Printing.html
*
* And also from a post on the forums at java.swing.com. My apologies that do not have
* a link to that post, by my hat goes off to the poster because he/she figured out the
* sticky problem of paging properly when printing a Swing component.
*/
import java.awt.*;
import javax.swing.*;
import java.awt.print.*;
public class PrintUtilities implements Printable {
private Component componentToBePrinted;
public static void printComponent(Component c) {
new PrintUtilities(c).print();
}
public PrintUtilities(Component componentToBePrinted) {
this.componentToBePrinted = componentToBePrinted;
}
public void print() {
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(this);
if (printJob.printDialog())
try {
System.out.println("Calling PrintJob.print()");
printJob.print();
System.out.println("End PrintJob.print()");
}
catch (PrinterException pe) {
System.out.println("Error printing: " + pe);
}
}
public int print(Graphics g, PageFormat pf, int pageIndex) {
int response = NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D) g;
// for faster printing, turn off double buffering
disableDoubleBuffering(componentToBePrinted);
Dimension d = componentToBePrinted.getSize(); //get size of document
double panelWidth = d.width; //width in pixels
double panelHeight = d.height; //height in pixels
double pageHeight = pf.getImageableHeight(); //height of printer page
double pageWidth = pf.getImageableWidth(); //width of printer page
double scale = pageWidth / panelWidth;
int totalNumPages = (int) Math.ceil(scale * panelHeight / pageHeight);
// make sure not print empty pages
if (pageIndex >= totalNumPages) {
response = NO_SUCH_PAGE;
}
else {
// shift Graphic to line up with beginning of print-imageable region
g2.translate(pf.getImageableX(), pf.getImageableY());
// shift Graphic to line up with beginning of next page to print
g2.translate(0f, -pageIndex * pageHeight);
// scale the page so the width fits...
g2.scale(scale, scale);
componentToBePrinted.paint(g2); //repaint the page for printing
enableDoubleBuffering(componentToBePrinted);
response = Printable.PAGE_EXISTS;
}
return response;
}
public static void disableDoubleBuffering(Component c) {
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(false);
}
public static void enableDoubleBuffering(Component c) {
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(true);
}
}
If you encounter trouble using this class, let me know. And if it helps you, let me know as well.
Tooty Fruity
Yes, I'm not generally all that shy about mentioning my own works. I am, of course, quite proud of a lot of them. Faulker said you have to kill your little darlings, or something to that effect. It's one of my favorite sayings. And sometime I have to kill my own little darlings, even when I'm oh, so proud. For example, we will soon be phasing out the set web application framework that I developed at work in favor of Struts.
I'm not sure that Swing is really out of date, though I'll be the fist to admit it's hard to use. Some would say that Java developers all need to rush to embrace the Eclipse SWT platform. I'm not so sure. I like Eclipse, but there is much I don't like about it. For example when you mouse over a particular component, you don't get automatic mouse wheel control of that component as you do in Swing. A small issue, I know, but a feature I really like. Anyway, I've never really tried to work with SWT.
I've heard there are WYSIWYG Swing development tools these days. I've never seen one that worked to any useful degree, but NetBeans is supposed to be very good these days.
As for locking you into a proprietary platform--Swing is part of Java. It's not a 3rd party tool at all. Yes, if you build your components using Swing, you'll always need to have the Swing classes to run them. But they should always be there in the JVM for you.
rob macgrogran's printing in java
I have very similar printerjob and print code, but because I want the report header with title and current page number repeating for each page, I place a "report" panel on a scrollpane that is on another panel. My printable component is set to the outer panel. I call printerjob.print, then, if there is still more to print I scroll the "report" panel forward a page worth and call printerjob.print again. This was working well for a couple of years until we got PC's running XP with processors that are 3000 MHz and greater. Now javaw crashes every few reports (sometimes 2, sometimes 5 will print successfully, whether or not they are multipage) on those machines. We suspect a race condition but have been unable to figure out a successful workaround as am not sure exactly where the race condition might be. Any thoughts?
(The processor speed is the only variable I have been able to identify so far that is common between those that work and those that do not work.Continues to work on Unix, Mac, NT, Windows 2000 and XP running processors
Printing in an independent process
Isn't there any way of telling whether the report header printing is done? By definition, almost, any sleeping will break on some future platform. Be honest with you, I'd rewrite the printer module rather than "reusing" something I cannot control.
If you are printing the header in a distinct thread, to me the ONLY solution is shared access to a semaphore which both processes access in an atomic operation, but if you don't have the code of the header module, this is impossible.
Can you redirect the printer code to spew out the report to a string? As it is, this system should not be attempting to multithread.
Just my two cents. I don't "understand" everything here in part because I only "understand" systems, especially in multiprocessing, when I've built them myself or had a guy like Dijkstra persuade me they are provably cool.
Re: Printing In Java
Sir,
I used your PrintUtilities class for html printing. But I am unable to print html file of multiple page through it. I only got printout of the first page of Html file. Could you please help me out to print multiple page html file.
Pls Reply back at following mail id.
Thanks and regards
Ssachin Sharma
sachin.sharma ~AT~ tatainfotech ~DOT~ com
Multi-Page Should Be No Problem
I don't know why it's not working for you. This class definitely allows me to print multi-page files. Are you sure the page is fully loaded before you try to start printing? Could that be your problem?
How to print localhost html file?
Rob,
I have a html file abc.html running at localhost, how do I print it with your code? Could I select a network printer defined on my machine and not have the print dialog show up?
Thanks!
Ing
You'll have to modify the cod
You'll have to modify the code a little bit to not have it show the print dialog. But, yes, you can specify the printer information in your code. Read up on javax.print.PrintService.
You can pass a PrintService object into a PrinterJob. Hopefully that will point you in the right direction.
Printing multi pages
I have a problem. when i run your code on a jtextarea i only get one page. could there be something i am missing?
Please help
Thanks
Rex
Re: Printing In Java
I just downloaded and implemented your code in my simple text editor.java application and it works just fine.
Many thanks for you saved me a lot of trouble.
I spent a lot of time reading and searching atricles and tutorials from all over the net and spent a lot of time on my java editor in the past few days.
Re: Printing In Java
[quote=]I just downloaded and implemented your code in my simple text editor.java application and it works just fine.
Many thanks for you saved me a lot of trouble.
I spent a lot of time reading and searching atricles and tutorials from all over the net and spent a lot of time on my java editor in the past few days.
[/quote]
Printing in Java is hell !!!!!!!!
I've been coding for over 20 years and almost exclusively in Java since '99. It's a wonderful language and platform. But printing in this language is sheer hell! I don't care what the width of the page is! I don't care how high the font is! I don't want to calculate the number of lines per page! and don't get me started on what the hell a glyph is! I JUST WANT TO PRINT THE TEXT CONTENTS OF A SWING COMPONENT!!!!!!!! Geez, you'd think I'd be asking to compute the sum total of grains of sand in the ocean at any given time! ......HEY SUN! We love you, but you let us down in this little area called printing. Fire those propeller heads you currently have in the PRINT shop and hire some normal developers with 1 head, two hands, and tons of requirements with absolutely no time to fool around with this crap you've given us.
...........ok. I'm done venting.
ANYONE: I have a simple JTextPane with text showing some XML text, it spans more than one page, I can not for the life of me print all of it's content. Got anything? Until then I'll forever stew over this crap we have to deal with in printing ANYTHING in java.
Ok, PrintUtilities did work
I cooled down overnight and found that the PrintUtilities above DOES work. It does lose a little of the bottom/top lines, but at this point I count this as a total score. WELL DONE AND THANKS!
p.s. Hey Sun, this does not at all retrieve the above sentiments. We in the real world just need to print stuff. Why all this creepy and unnecessary work!
Re: Printing in Java is hell !!!!!!!!
Hi everyone,
I know exactly what you mean. Anyways here is a useful link for you
http://www.daniweb.com/techtalkforums/thread23590.html
The thing is that it can't seem to print embedded jcomponents. I know i made a mistake some where in the views but i can't seem to figure it out. Maybe you can improve the code in the link and e-mail me an improved version of the code if you have found a way to print embedded jcomponents by improving the code.
Thank You
Yours Sincerely
Richard West
problem with the print class
Hi, the print class works fine except for one thing. It seems to break a page randomly - often in the middle of a line. Is there anyway to stop this from happening?
problems with print class
I want to print the content of a TextArea component (multi page)and
i get a blank page
what should i do
in have the code:
*****
void button1_actionPerformed2(ActionEvent e){
PrintUtilities.printComponent(ta);
}
****
ta it's a TextArea object
Please help me
Haven't Tried it with TextArea
I haven't tried the code with TextArea (or JTextArea for that matter). To be honest, I've only used it in one place. Don't mistake me for a Java printing guru. I'm not one. Try posting a question on java.sun.com or on a Java newsgroup. There are some smart people out there who are willing to answer all kinds of questions.
But don't expect anyone else to be familiar with my PrintUtilities class. Just ask a general question about printing the contents of a TextArea.
Printing JPanel containing Multiple components??
How do I print multiple components at a time?
Something like this,
JLabel
JLabel
JLabel JCheckBox JCheckBox JCheckBox JLabel
JTextPane
JTabel in JScrollpane Containing dynamic data along with JButton rendering.
JTextArea along with Jscrollpane having dynamic data
JLabel JLabel
JButton
Please help me on this
if html text have more than
if html text have more than one page , the text lines are broken in the middle and one line is placed in 2 pages....
HTML Printing
It probably does not directly answer your question, but this excellent article on A List Apart about printing HTML in book form with CSS might offer some helpful background information. My point is, I guess, that I doubt your Java-related HTML printing problem is unique, but rather generally a part of the challenge of printing HTML. As the article I linked to explains, there isn't really good support for HTML printing until CSS3, which has hardly been implemented by anybody. Perhaps there's a way to trick out the Java printing code (or roll your own--or open source?) to support CSS 3 for printing HTML. Just a thought...
Dan
i want output of my html report on my page through printer
i want output of my html report on my page through printer. can you please give one example.
An alternative to printing directly is to use PDF
I found the printing API so obtuse that instead I create PDF documents, and open the Acrobat viewer. The PDF format is very elegant, and one excellent library is http://www.lowagie.com/iText/faq.html. The only problem with this is sending documents directly to the printer, but perhaps there is a way.
printing in Java
Thanks a lot for your Printing utility, it works good. I just have a little defect that might not be from your code, but a Java bug; and that is that when I print a JPanel with several components the top margin seems to drift down every time the printDialog is called, so I actually get only part of the page that should be printed. In other JPanels of my application this doesn´t happen. I am kind of bugged onto this. I have the latest Java version (update 6) but keeps happening. Do you know of any workaround or cause for this happening?
Rob MacGrogans
Thanks for the printing utility. I used it to print for an application that needed to print JFrames and their contents.
It worked great with Netbeans 5.0.
One problem I encountered (my own fault) was caused by a lack of understanding of the coordinate transformations used in the Graphics2D API. If you are going to use the print utilities I suggest that you have a good understanding of transforms involving
rotation, scaling, etc.
The Scrub man
Thanks
Dear Sir,
I would just like to convey a hearty thanks for the information on your Blog. I have just spent the last 5-6 hours trawling Google trying to find code to print HTML from a JTextPane so you can imagine how happy I was when I plugged in this print Utility and everything began to run.
Kind Regards,
Gavin Rawson
Printing Text in java to a printer
I am writing a text editor and have got to the point where i want to print from my program.
The thing is that i have the java doc. but donot know where to begin from.
All i need is a piece of code to send the text from the JTextArea to my printer.
Help anybody
Duh?
Not to be rude, but duh, dude. The code is at the top of this thread.
Cut off words
Is there a fix/workaround for the cut off words(Half of a word at the top of a page and half at the bottom of the previous page)? I'm getting them in HTML and RTF.
Thanks
Chris
I have no succes ...
thank you for this article
but i tried to print and installed my printer
and no print action.
the java told me : there is no printers
How could i fix this problem ??
Mike's comment...
...reads like poetry.
hello all, While printing
hello all,
While printing JTable with header & footer, the header is printed in big fonts & in only one line. Hence it cuts the header message. I want to reduce header size or to print header in multiple lines.
Can any one help me?
Here is my Sample code:
String str_header = "Trial Balance for the period 1/Apr/2005 to 31/Mar/2006.";
MessageFormat header_MsgFormat = new MessageFormat(str_header);
String str_footer = "Page {0,number}";
MessageFormat footer_MsgFormat = new MessageFormat(str_footer);
try {
jtable.print(JTable.PrintMode.FIT_WIDTH,
header_MsgFormat,
footer_MsgFormat);
} catch (PrinterException e) {
e.printStackTrace();
}
thanks and regards
dayananda b v
Fixed So That HTML Images Work
For all you out there trying to print HTML Documents ... I fould a great example that expands on this one at this address, but it has a big problem with it. It won't print Images contained in the Html doc, at least not consistantly. After bagging at it for several days I found that if you modify the HtmlEditorKit's VeiwFactory to set it's ImageView's loadSynchro propery to true it works.
jeditorPane.setEditorKit(new HTMLEditorKit(){
public ViewFactory getViewFactory(){
return new HTMLFactory(){
public View create(Element elem) {
View view = super.create(elem);
if (view instanceof ImageView) {
((ImageView)view).setLoadsSynchronously(true);
}
return view;
}
};
}
});
just add that to where the jeditorPane is created.
Thank You!
Your code has helped me to print the Swing Component in many pages Thank you.
Sincerely,
A Abraham
How can I print multiple images in one page
Your print utility works fine. I am running into problems when I print two images on the same page.
I have included the following lines to print the second image:
// Shift the back image down by amount equal to the //height of the image + some spacing.
g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY()+ 450);
g2.scale(scale, scale);
drawBackImage(g2, backImage);
drawBackImage method :
private void drawBackImage(Graphics2D g, Image image) {
g.drawImage(image, 0, 0, 816, 324, this);
}
Any ideas why the second image size is half the actual size?
Thanks in advance.
BP
http://www.problemsolvingskill.net/
JasperReports
I am just wondering if JasperReports has been used by anyone. I found the documentation very confusing. Any pointers on this?
PrintUtilities seems to be good enough for simple printing in thin client applications.
There is also Eclipse BIRT that has plugin which helps in design of reports and server-side generation of documents. The problem is that the deployment is documented and tested only for Tomcat and JBoss. But the requirement in my current project has to accommodate all application servers.
Thanks,
BP
Good Stuff
Jasper Reports is good stuff. This is one of my favorite Java open source projects right now. I found the documentation to be pretty good, actually. And there are some free visual design tools that plug into it. We're using this in a project right now and I couldn't be happier with it.
Prints only 1 page..
I want to print all the content in a ScrollPane. But the script only prints the first page..
Is this the right way to retriev the content?:
PrintUtilities.printComponent(gui.textScrollPane.getViewport().getView());
Printing an HTML file on click
Hi - I read your blog. No doubt you are very good at this stuff. I however am a know-nothing attorney who needs to figure out how to get an HTML file to print from my website when users click on a link. For example, I have an html file in a folder on my server. I have a separate html file in the same folder that users view. In that second html file, I would like to put a link the says "Print Full Document." When users click this link, I would like the computer to go look at the 1st Html document and print it out. But I don't know how or where to start. Help. Please take pity on this lowly non-techy barrister. I'll promise to do more prop bono work.
JavaScript is Probably What You Want
The Java printing being discussed in this thread is a whole other animal, different than what you're trying to do. It sounds like you need something more like this:
http://www.dynamicdrive.com/dynamicindex9/other1.htm
Another common solution to this dilemma is to simply offer a "printable version" of a page (typically one stripped of menus, ads, etc.) and then just let the user click on the File->Print menu themselves.
Best of luck,
Dan
Printing beyond the margin
Does anyone know how to override the page default and print in the gutter / left margin area? I want to be able to print closer to the edge of the page, but nothing I have tried seems to have any effect on the page default, and my graphic is clipped.
Any help would be appreciate!
Vinny
Printing beyond the margin
You could do that by passing an extra PageFormat argument to printJob.setPrintable:
(Add code to public void print(), values are arbitrary)
public void print() {
PrinterJob printJob = PrinterJob.getPrinterJob();
PageFormat format = new PageFormat();
// or if you like:
// PageFormat format = printJob.pageDialog(printJob.defaultPage());
Paper pp = new Paper();
pp.setSize(597,835);
pp.setImageableArea(36,36,525,763);
format.setPaper(pp);
printJob.setPrintable(this,format);
etc.
Works Great - Thanks
Just wanted to thank you for the useful print utility - it works great for me. Hopefully Sun will listen to the pain of the Java developers out there and beef up printing support since they seem to be getting more serious about Java on the desktop.
unable to print from JBoss in swings
we are trying to print data using swings, we successed in jRun , if deploy the same code in jBoss we are getting this error :
sun.misc.ServiceConfigurationError: javax.print.PrintServiceLookup: : java.io.FileNotFoundException: http://devuc.corporate.ge.com/ftlt/META-INF/services/javax.print.PrintServiceLookup at
sun.misc.Service.fail(Unknown Source) at
sun.misc.Service.parse(Unknown Source) at
sun.misc.Service.access$100(Unknown Source) at
sun.misc.Service$LazyIterator.hasNext(Unknown Source) at
javax.print.PrintServiceLookup$1.run(Unknown Source) at
java.security.AccessController.doPrivileged(Native Method) at
javax.print.PrintServiceLookup.getAllLookupServices(Unknown Source) at
javax.print.PrintServiceLookup.lookupDefaultPrintService(Unknown Source) at
sun.print.RasterPrinterJob.lookupDefaultPrintService(Unknown Source) at
sun.awt.windows.WPrinterJob.getPrintService(Unknown Source) at
sun.print.RasterPrinterJob.print(Unknown Source) at
sun.print.RasterPrinterJob.print(Unknown Source) at
presentation.BaseFrame.doPrint(BaseFrame.java:1068) at
presentation.MainFrame.JMenuItemPrintDataSet_actionPerformed(MainFrame.java:1368) at
cmpresentation.CMMainFrame.access$33(CMMainFrame.java:1) at
cmpresentation.CMMainFrame$SymAction.actionPerformed(CMMainFrame.java:850) at
javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at
javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source) at
javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at
javax.swing.DefaultButtonModel.setPressed(Unknown Source) at
javax.swing.AbstractButton.doClick(Unknown Source) at
javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source) at
javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(Unknown Source) at
java.awt.Component.processMouseEvent(Unknown Source) at
java.awt.Component.processEvent(Unknown Source) at
java.awt.Container.processEvent(Unknown Source) at
java.awt.Component.dispatchEventImpl(Unknown Source) at
java.awt.Container.dispatchEventImpl(Unknown Source) at
java.awt.Component.dispatchEvent(Unknown Source) at
java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at
java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at
java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at
java.awt.Container.dispatchEventImpl(Unknown Source) at
java.awt.Window.dispatchEventImpl(Unknown Source) at
java.awt.Component.dispatchEvent(Unknown Source) at
java.awt.EventQueue.dispatchEvent(Unknown Source) at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source) at
java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at
java.awt.EventDispatchThread.pumpEvents(Unknown Source) at
java.awt.EventDispatchThread.pumpEvents(Unknown Source) at
java.awt.EventDispatchThread.run(Unknown Source)
Many thanks for this page
As anyone in this page I struggled to print a multi page file in Java. The doc is too complicated and you feel like roaming in a desert.
This page is a glass of cool water! It points to the essential of printing in Java. SUN should add it to it's site as a starting example.
Thanks to you. I think now I can go further by my own.
Creating a gif out of a java Map
I want to create a gif in byte[] from a map having name value pairs like;
FirstName: Joe LastName: Doe
Date of Birth: 2006-23-1967
..
any suggestions..
Thanx!! in advance.
-AJ
How generate report in java(swing)
Hi
I am kaveri, I am working in some company, just i want sample code for generate report in java, i can display my data in JTable but, number fo table colum is fixed, so i want number of table colum diffent row diffent colum, so anybody have code for this problem,pls send to my id kaveridpimku@gmail.com/kaveridpi_mku@yahoo.com
BY
M.kaveri
cannot say thank you enough
hi, i just want to drop a reply saying THANK YOU for your article above.
i really want to thank you million for excellent effort you put in. both PSwing and printing class is EXACTLY what i am looking for in my project.
again, thank you so much
Question regarding your print code
First of all. You are completely right regarding printing in JAVA. At the moment Im making an application, which should print a JScrollPane. Well your code seems good, but a get a problem when printing:
The whole scrollpane prints on one page, so it gets very small and unreadable. Any ways to make it larger, and print it on multiple pages... Maybe its just my problem. But at least it prints the entire scrollpane out, instead of just printing the current view. GOOD!!!
im using this:
PrintUtilities pu = new PrintUtilities(histogram);
pu.printt();
I cant get this function to print anything:
public int print(Graphics g, PageFormat pf, int pageIndex)
Do you maybe have some sample code on how to use it???
I have tried to do this:
PageFormat pf = new PageFormat();
PrintUtilities pu = new PrintUtilities(histogram);
pu.print(histogram.getGraphics(),pf,1);
nothing happens ??
Please reply
Dont works for me
I am trying to print with your class like this:
new PrintUtilities(new JLabel("Test")).print();
Printing is invoked right with the dialog, but only an empty white page is printed.
What is the problem?
Toot
Please feel free to toot away. Part of the problem is indeed the psychology instilled, that to say (or most especially write) about one's trade is Vanity and likely to expose one to the scorn of the Mob, as one who would toot his own horn. The silenced are then taught to write and to speak on behalf of organizations alone.
My experience with Eclipse has been very positive so far although the product on which I work doesn't coordinate as smoothly as does Visual Studio when the developer changes the code, as opposed to manipulating the GUI. Basically, to be ready for prime time, the Eclipse-based application needs to contain the Document Object Model equivalent representation of the parsed code.
My understanding of Swing is that it is slightly out of date, locking one into the Swing-proprietary platform: please confirm or deny.
Code looks great to me but I don't "do" a lot of Java.