How to print the whole JFrame
Hi,
I got this code somewhere from the net.
import java.awt.*;
import javax.swing.*;
import java.awt.print.*;
/** A simple utility class that lets you very simply print
* an arbitrary component. Just pass the component to the
* PrintUtilities.printComponent. The component you want to
* print doesn't need a print method and doesn't have to
* implement any interface or do anything special at all.
* <P>
* If you are going to be printing many times, it is marginally more
* efficient to first do the following:
* <PRE>
* PrintUtilities printHelper = new PrintUtilities(theComponent);
* </PRE>
* then later do printHelper.print(). But this is a very tiny
* difference, so in most cases just do the simpler
* PrintUtilities.printComponent(componentToBePrinted).
* 7/99 Marty Hall, http://www.apl.jhu.edu/~hall/java/
* May be freely used or adapted.
public class PrintUtilities implements Printable {
private JFrame componentToBePrinted;
public static void printComponent(JFrame c) {
new PrintUtilities(c).print();
public PrintUtilities(JFrame componentToBePrinted) {
this.componentToBePrinted = componentToBePrinted;
public void print() {
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(this);
if (printJob.printDialog())
try {
printJob.print();
} catch(PrinterException pe) {
System.out.println("Error printing: " + pe);
public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
if (pageIndex > 0) {
return(NO_SUCH_PAGE);
} else {
Graphics2D g2d = (Graphics2D)g;
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
disableDoubleBuffering(componentToBePrinted);
componentToBePrinted.paint(g2d);
enableDoubleBuffering(componentToBePrinted);
return(PAGE_EXISTS);
/** The speed and quality of printing suffers dramatically if
* any of the containers have double buffering turned on.
* So this turns if off globally.
* @see enableDoubleBuffering
public static void disableDoubleBuffering(Component c) {
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(false);
/** Re-enables double buffering globally. */
public static void enableDoubleBuffering(Component c) {
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(true);
}From my main class (where the JFrame resides), the print() method is invoked to print the JFrame. However, when it is printed, it only prints the top left part of the JFrame, not the whole JFrame. Can anyone help please? Thank you very much.
public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
if (pageIndex > 0) {
return(NO_SUCH_PAGE);
else {
Graphics2D g2d = (Graphics2D)g;
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
double xScale = 0.63;
double yScale = 0.56;
g2d.scale(xScale, yScale);
disableDoubleBuffering(componentToBePrinted);
componentToBePrinted.paint(g2d);
enableDoubleBuffering(componentToBePrinted);
return(PAGE_EXISTS);
}Hi all,
Alright I managed to scale it to print the whole JFrame. But another problem surfaces. When I select draft quality printing, it doesn't print the whole JFrame. Other printing qualities (standard, high) do print the whole JFrame. I am really puzzled. Anyone has any clue?
And I have an unrelated question to this topic. How do I set a JTextField so that when I click on it the first time, it highlights its content? Have to work around with the mouselistener?
Thank you.
Similar Messages
-
How to Print the whole view content from a button on the View Layout
Dear All,
Good Morning All
I am New to WebDynPro.Solution needed Urgently
How to take print whole view content(lay out) in
webdynpro application.i.e whatever it may be tablecontent or label or inputfield .
Could you send the coded part briefly step by step from the beginning itself i.e
i put the button in the view lay out below the printed parts(label or inputfield) name like show preview .
Now my Question is what should i write in show preview function to take the print in label fields in the webdynpro view lay out
B'cos i am new to webdynpro.Help me
Thx in advance
Regards
DhinakarWeb Dynpro by default does not provide the option of printing the view content.
However still you have a round about way of doing it. Create the an html page similar to the Web Dynpro page. Store the code into a String variable.
String html="<html> ....<scripts>window.print()</scripts></html>";
bytes[] source=html.getBytes();
try{
byte[] b=new byte[1];
IWDCachedWebResource res=WDWebResource.getWebResource(b,WDWebResourceType.HTML);
String url=res.getURL();
}catch (WDURLException e) {
// TODO: handle exception
Now open the url in a new window and that would print the content of the html page.
Regards,
Noufal -
How to Print the whole view content from a button on the view
Dear All,
Good Morning All
I am New to WebDynPro.Solution needed Urgently
How to take print whole view content(lay out) in
webdynpro application.i.e whatever it may be tablecontent or label or inputfield .
Could you send the coded part briefly step by step from the beginning itself i.e
i put the button in the view lay out below the printed parts(label or inputfield) name like show preview .
Now my Question is what should i write in show preview function to take the print in label fields in the webdynpro view lay out
B'cos i am new to webdynpro.Help me
Thx in advance
Regards
DhinakarWeb Dynpro by default does not provide the option of printing the view content.
However still you have a round about way of doing it. Create the an html page similar to the Web Dynpro page. Store the code into a String variable.
String html="<html> ....<scripts>window.print()</scripts></html>";
bytes[] source=html.getBytes();
try{
byte[] b=new byte[1];
IWDCachedWebResource res=WDWebResource.getWebResource(b,WDWebResourceType.HTML);
String url=res.getURL();
}catch (WDURLException e) {
// TODO: handle exception
Now open the url in a new window and that would print the content of the html page.
Regards,
Noufal -
When I AirPrint The printer only prints a portion of the page. How do I get it to print the whole page.
It would help if you stated what printer you are using and what application you are doing the printing from. Also, what are you printing?
-
how do i get it to print the whole article? i don't seem to have a problem printing from my old windows laptop
melbaby_3 wrote:
when I clicked on your link and hit print, all pages were there!
That suggests there's no problem with Safari or Quartz, the PDF rendering engine used by Safari, Preview, and other Mac applications.
When I'm in the database and have the article open that I want to print, I click on the "full text in pdf" link and it opens in another safari window.
Does the PDF in this other Safari window have all the pages? If yes, why don't you print from this window?
It's very difficult to tell what might be going on if you don't give very specific details.
For instance, in many reference databases, full-text articles are not free. You have to pay to view them, either article by article, or by subscription. Your school may have such a subscription, but, if it does, you probably need to access the database through the portal, web site, or facility provided by your school (your school's librarian should be able to help you with that). If you don't, the database has no way of knowing you have a right to view the full text, and may give you just a preview or the article's first page.
Another possibility is that the database provides full-text PDFs in a format not compatible with Quartz, which may be able to render only the first page. But, in such a case, I'd expect Safari to print blank pages. If that's the case, you need to save the PDF on your hard disk and open it with Adobe Reader (Preview wouldn't work).
There are other possibilities, but these two seem to me the most likely.
Would I have to save it in preview first
You should save the PDF on your hard disk from Safari. (I think you should do this anyway, just in case you need to refer to the article again later.) Instead of just clicking the "'full text in pdf' link", press and hold Control, then click. This should give you a contextual menu; if the link points to a PDF file, you should see the commans "Save Linked File to 'Downloads'" and "Save Linked File As…". Use either, save the file, then, in Finder, double-click on it. Preview should open it.
It is possible that the link is not to a PDF file, but to a script which fetches that PDF file for you. In that case, it's pointless to download it. Click on it, and then, if the PDF viewing window opens in Safari, move the cursor towards the centre of the bottom of the window. A bar with commands should appear; one of them will download the file to your Downloads folder. -
I frequently have a need to print a portion of a spreadsheet for a presentation, but find that I have to print the whole spreadsheet page to obtain the information I want. When I was using Microsoft Excel I could highlight a section of a spreadsheet and print only the highlighted rows. Is there some way that I can do this in Numbers? Help will be appreciated.
Numbers differs significantly from Excel in the print paradigm. If you enable Print View using the menu item "View > Show Print View", you will see exactly how each page will print.
A Numbers document contains Sheet.
Sheets contains a canvas, on which you place tables, graphics, text, and media. The canvas is continuous and is divided into pages at print time.
If you want to print just a portion of a table, select the area, copy, the open the Application Preview, select the menu item "File > New From Clipboard"
Then print -
When I try to print a photo from iphoto, I click print and the preview shows a lot of the photo cut off. It also prints this way. How can I print the whole photo?
After selecting File > Print, a pop-up window should appear. Select "Customize" and this should take you back into a panel within iPhoto. Towards the bottom, you should see an option for "Layout". Select this option and choose the correct photo orientation.
Hope this helps! -
When I print a PDF downloaded from the internet it chops the bottom RH corner of the page and reproduces it 6x (2x across the page and 3x down the page), instead of printing the whole page, this is driving me mad, does anyone know how to stop it? I have ticked Print as Image and Multiple Pages is NOT selected....
suzbat,
I have ticked Print as Image and Multiple Pages is NOT selected....
Are you using the desktop version of Adobe Reader on a Mac computer? What is the version of your Adobe Reader?
You posted the question on the Adobe Reader for iOS forum. But Adobe Reader for iOS does not offer the print options like "Print as Image", "Multiple Pages". -
How to Print the text in a Text Area Component
It is really amazing how much information is out there for
Flex but you can never find what you are looking for :-(
I am trying to print the contents of a text area component.
If I just do addPage(Component Name) it works but it prints the
whole conponent including the scrollbars, on the page. I just want
the text. If I try to put the component name.text in addPage(), I
get a "1067: Implicit coercion of a value of type String to an
unrelated type flash.display:Sprite." error. Does anyone know how
to do this?
Any help would be greatly appreciated.
DaveIs there anyone who can help with this? I really need a way
to print the results.
Thanks.
Dave -
How to print the output of the screen in Dialog Programming
Hi,
Could anybody help how to print the output of a screen in the dialog programming. i can select 'Hard Copy' option in the 'Custumizing of Local Layout' Icon in the standard tool bar. but that prints the whole screen with the toolbar. i want to print only the output which is displayed on the screen. Please help..
Regards,
SwathiHi Swathi,
Ok. Do One thing. Go to menu bar and select Systems -> Own pool Request -> here you get the spool number. Select it and select the option "Print Directly" in tool bar.
Thanks. -
How to print the superscript in smartform
Hi gurus,
Please tell me the procedure how to print the superscript in middle of the text displaying?
when we are displaying the smartform its converted to some special character like & .
please let me know procedure at the earliest
Regards
RajHi thanks for ur patience.
see my requirment was to print TM as superscript for HLL ,already smartstyle is there, and also a character format with superscript is also defined.
then aftet HLL how it prints as superscript.
for HLL we are using another character format and for superscript we are using the another character format.
If posiible send me the code to write in smartforms
Regards
RAj
Points are awarded for useful answers. -
How to print the script in condensed mode
Hi to all,
Pls help me.
How to print the script in condensed mode and particular window only print in the condensed mode.Hi,
Hi
It will remove the blank spaces in front of the variable
and if you use the extension NO-GAPS
It will remove all the blank spaces in the variable field.
DATA: ws_val1 type char12.
ws_val1 = ' 100 123'.
Condense ws_val1.
Write / ws_val1.
Condense ws_val1 no-gaps.
write / ws_val1.
It will give output as
100 123
100123
The CONDENSE statement deletes redundant spaces from a string:
CONDENSE c NO-GAPS.
This statement removes any leading blanks in the field c and replaces other sequences of blanks by exactly one blank. The result is a left-justified sequence of words, each separated by one blank. If the addition NO-GAPS is specified, all blanks are removed.
Please check this link for sample code.
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb33e6358411d1829f0000e829fbfe/content.htm
Regards,
Raj. -
How to print the text in points wise in sap script
hi friends,
how to print the text in points wise in sap script.
ex: if suppose paragraph consists of 15 lines. then according to one sentence or one fullstop (.) it should give point 1. like that...
1. hai how ru.
2. what r u doing.
3.where r u.
like this i want numbering.. waiting for ur replys.
thanks,
kirandeclare a counter
data : cnt type char 4.
print :
cnt = cnt + 1.
&cnt& &text&
cnt = cnt + 1. and so on.
or.
if the data is in an internal table
loop at internal_table.
cnt = cnt + 1.
write form.
in script -&cnt& &text&
endloop.
Edited by: NIKHILKUMAR POOJARI on Nov 17, 2008 11:18 AM -
How to print the text in only last but one page in sapscripts
hiiiiiiiiiii,
explian how to print the text in only last but one page in sapscripts? wher to write the code? plz if possible explain in detail with an example?Hello,
The total no pages is given by &SAPSCRIPT-FORMPAGES& command.
So u can handle the situation in ur form like this
/: if &PAGE& = &SAPSCRIPT-FORMPAGES&
p1 TEXT
/: endif
Try in this way it may help u.
Regards -
How to print the message in 2 lines?
How to print the message in 2 lines?
Here i am having it like this... MESSAGE i000(zm) WITH lv_uname.
here I want to print lv_uname in 2 lines because it lengthy one.
Thanks,
Sridhar.No man, itas not comming..I am using the below logic to print my message:
CONCATENATE text-I01 lv_printdate1 text-I02 INTO lv_printname
SEPARATED BY space.
MESSAGE i002(zm) WITH lv_printname.
its printing in a single line...
Maybe you are looking for
-
PLEASE HELP ME I HAVE NO IDEA WHAT TO DO!!!!PLEASE?!?!
I HAVE A ROUTER THAT IS RUNNING TWO LAPTOPS AND A DESKTOP. I PUT A W-E-P 128 BIT PASSWORD ON IT AND I DON'T WANT IT TO HAVE A PASSWORD! HOW DO I REMOVE SAID PASSWORD BEFORE MY PARENTS FIND OUT I LOCKED UP THEIR BUSINESS ROUTER?
-
File.exists() and accent on unix
Hi, I made a main which test if a file exists. I created files "toto" and "tété" on windows. On windows the two files are seen. I transfered them on a redhat. The file "toto" is seen but "tété" is not. Here is the code : public static void main(Strin
-
Iphone5 ... I can not connect to itunes store?
ON MY iphone 5 I can not connect to the iTunes store
-
How to find exact query executed by reports with parameters
Hi, I am running a report which errors out with below log messages. REP-0004: Warning: Unable to open user preference file. REP-0300: ORACLE error occurred. REP-0069: Internal error REP-57054: In-process job terminated:Terminated with error: REP-300:
-
HT1904 I have unauthorized charges to itunes store currently in dispute please advise.
I have unauthorized charges to itunes store,please advise.