wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes problem in printing swing components? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problem in printing swing components?" Watch "problem in printing swing components?" New topic
Author

problem in printing swing components?

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1002
    
    2
i have a registration page, and after registration of a student i need to print the tc (transfer certificate), in the (Photo1430.jpg) image format, (in the same format shown in the image).
field values are coming from the database.(ie. value of name, value of dob, value of place so on...)

i am doing something like this:



this code giving me output like this the below image(output.png):
i am just trying to achieve, what i want(like in my first image(Photo1430.jpg)), so what i have not added all the component to my code (just testing).

Ouestions:-
it will print from the top left corner of page(leaving the default printer margin), what i need to do to give a header space (say, 2 inch or 144 points)??
m i doing this right way to achieve my desired output??
also how do i add values of my fields over the dots??

output.PNG image is what i am doing and Photo1430.jpg is what i want.
Thank you..


[Thumbnail for Photo1430.jpg]

[Thumbnail for output.PNG]

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> i am doing something like this:

that's what's annoying, why don't you post the actual code, not 'something like'

look at the posted code, at the top of PrintUIWindow()
JFrame frameToPrint;

then in main()
JFrame f = new JFrame("Print TC");
which is the frame on the screen, the one with the print button

then the print code
frameToPrint.printAll(g);

so how can you possibly print anything out?

anyway, the clue to what you want is in the name 'frameToPrint'
i.e. if you don't want the frame printed, what do you think might go there instead?

also, you might want to change this line (not part of the problem, but think about it)
panel.add("South", printButton);
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1002
    
    2
but michael i can't check it, because i have no pritner attached to my laptop.
and my question is how i will get the layout something like which is in Photo1430.jpg.
i mean the dotted lines and the field values over them??
also how i will get like in that image at point number 3,(multiple lines), and also at point number 8 (the rectangle type table) with dynamic values.?
and my main frame has border layout, and has menu at the top, which has print menuItem, and by clicking on that i am changin the BorderLayout.CENTER to my PrintReport class.

PrintReport.java


Above is the class which i am attaching to my main frame/class.
i am not able to get layout like that image.
can i print panel, i am printing panel here but not working.??

Thank you..
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> my question is how i will get the layout something like which is in Photo1430.jpg

a JTextPane might be your best bet - you should be able to format it, add tables etc,
so that it looks like the photo image, then print out the textPane
Tobias Leon
Greenhorn

Joined: Apr 17, 2012
Posts: 22

Hi there !!!
You need to print your GUI ???

Or maybe you should to try with a Report maker, like Ireport.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1002
    
    2
hii michael

a JTextPane might be your best bet - you should be able to format it, add tables etc,
so that it looks like the photo image, then print out the textPane.


yes it makes my work, i use jeditorpane.
i found one interesting for this on the internet, and make some changes into that.
i m posting the working code, how i did.
below is the working code, if anyone wants.

TestPreview.java


PrintPreview.java


working code with print preview, i am just taking the values from the database.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1002
    
    2
hii tobian

You need to print your GUI ???

yes..

Or maybe you should to try with a Report maker, like Ireport.


yes i thought to use them, but the problem i m getting is to create installer for the software.
if i use ireport i need to attach the jar also, when i create the installer, and i am facing difficulties in attaching the jars.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in printing swing components?