How to print the JFrame In The Center Of The Page?

hi there in the following code iam trying to print a JFrame
but the frame appear in the printed page at the top left
and i want it to appear in the top center of the page
how to do that?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.print.*;
class PrintUIWindow implements Printable, ActionListener {
    JFrame frameToPrint;
    public int print(Graphics g, PageFormat pf, int page) throws
                                                        PrinterException {
        if (page > 0) {
            return NO_SUCH_PAGE;
        Graphics2D g2d = (Graphics2D)g;
        g2d.translate(pf.getImageableX(), pf.getImageableY()-55);
        frameToPrint.print(g);
        return PAGE_EXISTS;
    public void actionPerformed(ActionEvent e) {
         PrinterJob job = PrinterJob.getPrinterJob();
         job.setPrintable(this);
         boolean ok = job.printDialog();
         if (ok) {
             try {
                  job.print();
             } catch (PrinterException ex) {
    public PrintUIWindow(JFrame f) {
        frameToPrint = f;
    public static void main(String args[]) {
        UIManager.put("swing.boldMetal", Boolean.FALSE);
        JFrame f = new JFrame("Print UI Example");
        f.addWindowListener(new WindowAdapter() {
           public void windowClosing(WindowEvent e) {System.exit(0);}
        JLabel label1=new JLabel("Selling Bill",JLabel.CENTER);
        JLabel label2=new JLabel("Customer Name :Mahmoud Saleh       ",JLabel.LEFT);
        JLabel label3=new JLabel("Buying Date :29/8/2008             ",JLabel.LEFT);
        JLabel label4=new JLabel("Book Buyed :Java Printing          ",JLabel.LEFT);
        JLabel label5=new JLabel("Number : 6 Copies                  ",JLabel.LEFT);
        JLabel label6=new JLabel("Total Price :600 $                 ",JLabel.LEFT);
        label1.setFont(new Font("Courier New", Font.BOLD, 13));
        label2.setFont(new Font("Courier New", Font.BOLD, 13));
        label3.setFont(new Font("Courier New", Font.BOLD, 13));
        label4.setFont(new Font("Courier New", Font.BOLD, 13));
        label5.setFont(new Font("Courier New", Font.BOLD, 13));
        label6.setFont(new Font("Courier New", Font.BOLD, 13));
        JButton printButton = new JButton("Print This Window");
        printButton.addActionListener(new PrintUIWindow(f));               
        JPanel panel=new JPanel();
        panel.setLayout(new GridLayout(6,1));
        panel.add(label1);
        panel.add(label2);
        panel.add(label3);
        panel.add(label4);
        panel.add(label5);
        panel.add(label6);
        f.setSize(300,300);       
        f.setLocationRelativeTo(null);       
        f.add(panel,BorderLayout.CENTER);
        f.add(printButton,BorderLayout.SOUTH);
        panel.setBackground(Color.WHITE);
        f.setResizable(false);
        f.setVisible(true);
}

First_knight wrote:
please tell me am i thinking right
about this method: setImageableArea(.....)
public void setImageableArea(double x, double y,  double width, double height);
like I said, I've tried this method and it doesn't seem to do anything.
the width=the JFrame Width,the height=the JFrame Height right?actually, when printing, 72 points (printing version of pixels) = 1 inch, so to do WYSIWYG, you need width = JFrameWidth * 72.0 / Toolkit.getToolkit().getScreenResolution. Ditto with height
upper left beginningx(0)---------------------------200--------------------------------600-----------------------------------y(1000)upper right beginningyou need to do something like PageSetup.getImageableX and do Graphics.translate(x,y);
also, if your page width = 720, that = 10 inches - that's a wide page (unless its in landscape)
so if i want the JFrame To Be In The Center Of The Page I Would Choose From x=200 ,y=600 depending that frame width is 400Actually, it would be 300 - 700 in your example
Because when i tried to use:setImageableArea(200, 600,  400, 200);like the above code
no changes occurs in the printed paperYes. You need to offset the Graphics object

Similar Messages

  • Can anybody explain how to print multiple copies of different documents at the same time as at the moment I have to open each individually and press print

    Can anybody explain how to print multiple copies of different documents at the same time as at the moment I have to open each individually and press print

    is this a windows in bootcamp question ?

  • Unable to open the Projects from Project center with the Alias name PWA 2010

    Hi,
    I am unable to open the Projects from Project center with the Alias name with the server name i am able to open the projects, version is  project server 2010,
    My system is ABC.DC.IN  alias name i have given is DEF.AD.COM  
    With the system name i can able access PWA and all are working fine.
    As i have observed with alias name i can able to login to  pwa and all the server  setting approval center all are working fine but only in the project center i am not able to open the projects (http://DEF.AD.COM/pwa/ProjectDrillDown.aspx .xxxx) its
    is coming in the below of the ie. 
    But with Alias name these are the issues i am facing,
    1.when longing with alias name its asking two times for user name and password
    2.when i click on a project from project center its taking some time and asking for user name and password after i enter user name and password "PAGE cannot displayed" error i am getting.
    3. I have observed one more thing if click on Project details then only this issue  is coming project schedule and project information is also opening with Alias name.
    can any one Help me. 
    Vijay kommireddi

    Hi
    Hope the below link will help you.
    And also please check the browser which you are using as mostly IE 8.0 won't support, Please try it in IE 9.0 and Chrome.
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/c03300d2-2a27-4d5d-b3f6-a3660805e125/alternative-access-mapping-when-accessing-the-site-it-is-asking-for-username-and-password
    Thanks
    Geeth If you feel that the answer which i gave you is Helpful please select it as Answer/helpful.

  • How to print grandtotal in table footer only in the last page in SMARTFORMS

    Hello Experts,
    How do I print the GRANDTOTAL in the table footer only on the LAST PAGE in SMARTFORMS.
    What I have done is in the text element of CELL1 of the table footer i wrote the folowing logic but not working.
    /: IF &SFSY-PAGE& EQ &SFSY-FORMPAGES&.
    * V_SUM.
    /: ENDIF.
    I even tried this.
    /: IF &NEXT-PAGE& EQ 0.
    * V_SUM.
    /: ENDIF.
    but still it displays the grand total on all pages at table footer.
    How do i go for this experts.
    Regards,
    Ranjith N

    HI Nambiar,
    To print the grand total only on the last page then create the secondary window --> create the text node for the grand total -->In the condition tab check only after the end of the main window.
    This grand total will be displayed after all the items and end of the main window.
    Footer in the table displays as the subtotals i.e on every page total is displayed..
    Regards,
    Sravanthi

  • ADF: How to print query and query parameters passed in the executeQueryForCollection methof of VO impl class.

    Hi,
    Kindly let me know how to print the query and the parameters passed to it? I tried with the params parameter in super.executeQueryForCollection(qc, params, noUserParams); but could not succeed.
    I need to log the query and the params passed to it. Kindly help.
    Thanks in advance,
    Kalpana.

    Here you go
    Coding With Passion: Oracle ADF - Debug view object query with parameters

  • Why won't the container and header center on the screen?

    I put together a very short file while trying to learn to code in CSS.  I'm baffled that the container won't center.
    Here is the code...
    <html>
    <head>
    <title>practice3</title>
    <title></title>
    <style>
    body{background-color:#2c344f; text-align:center; font-family: "Arial"}
    H2 { color:#963}
    DIV {padding: 15px; margin: 5px; background-color:#f8f7ee}
    IMG {margin:0 auto}
    div#header {width:780px; text-align:center; background-color:#f8f7ee}
    div#container{ text-align:center; width: 780px; margin: 0 auto}
    </style>
    <DIV ID="header"><img src="newbirdsonyellow.jpg" align="center" width="741">
    </div>
    </html>

    Why place a separate wrapper div into the document...?
    Short answer, better control.
    Consider the following scenarios:
    #1 I need to use 2 or 3 different background images on my page.  Until CSS3 gains better browser support, a  div can't have more than one background.
    #2 I want my body to be 100% of viewport while my content is fixed-width and centered.
    #3 If I use a fixed, centered background on my body, the background image slides off to the left when viewport is minimally resized.  Try it with the link below:
    http://alt-web.com/DEMOS/fixed-background.shtml
    #4 I have some APDivs in my layout.  To control them, I need to wrap them inside a relatively positioned division.  See disjointed rollover example:  http://alt-web.com/DEMOS/CSS-Disjointed-Image-Gallery.shtml
    #5 I have some floated boxes in my content region. To control the space between them, I need to wrap them inside a fixed-width division that is smaller than my page. See CSS boxes example. http://alt-web.com/DEMOS/3-CSS-boxes.shtml
    These a just a few situations in which having a #wrapper is better than not having one.  Your mileage may vary.
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    http://alt-web.com/
    http://twitter.com/altweb

  • Alignment of the af:popup in Center of the browser

    hi all,
    Can anyone let me know what is to be done to get the popups poping in the center of the page from wherever link it is clicked.
    my code below:
    <af:commandLink text="#{ladwp.HOW_TO_FIND_QUOT_BILLDATE}" id="cl1" immediate="true" inlineStyle="color:#0079c2">
    <af:showPopupBehavior popupId="billingInfo" triggerType="action"
    align="afterStart" alignId="cl1"/>
    </af:commandLink>
    <af:popup id="billingInfo">
    <af:dialog contentHeight="200" contentWidth="500" type="none"
    styleClass="#{Localization.language=='en'?'popUp':'popUpES'}">
    <af:panelGroupLayout id="pgl26" layout="vertical" valign="top">
    <h5 class="gFix">
    <af:outputText value="#{ladwp.HOW_TO_FIND_QUOT_BILLDATE}" id="ot40"
    inlineStyle="color: #0079c2;font-size:large"/>
    <af:spacer width="10" height="10" id="s13"/>
    </h5>
    <af:outputText value="#{ladwp.YOU_MAY_LOCATE_YOUR_BILL_DATE}"
    id="ot39" styleClass="trainLabelsBill"/>
    <!-- <af:spacer width="20" height="10" id="s15"/>
    <af:outputText value="#{ladwp.YOUR_AMOUNT_DUE_IS_LOCATED}" styleClass="trainLabels"
    id="ot1"/>-->
    <af:spacer width="10" height="50" id="s18"/>
    <af:panelGroupLayout id="pgl27" layout="horizontal">
    <af:image source="/oracle/webcenter/portalapp/shared/images/billing_Inquiry.png"
    shortDesc="bill" id="i3"/>
    </af:panelGroupLayout>
    </af:panelGroupLayout>
    </af:dialog>
    </af:popup>
    Please it is urgent for me.
    Thx,
    Asha

    No, if the link opening popup is in the center of page ,then it is proper centered . but if the link is sumwer up or down then it is centered but only horizontally not vertically in middle of browser.
    -Asha

  • How to print blank line on BIP template when the field has no value?

    I have a BIP template like below and all these CHILDREN, NAME, GRAND_CHILDREN, NAME are fields arranaged in the template as a row.Reps can enter values in each of these fields for a max upto 3 rows. The first 2 rows have the values and the last is blank.
    CHILDREN: NAME: GRAND_CHILDREN: NAME:
    Son     John Daughter     Smith
    Daughter Laura Son      Kevin
    In the third row since the fields have no values, the report print blank rows, but I want to delete that blank row and show only the rows(first 2 rows) that have values for the fields.
    Does any one know how to get around this? Please help me to resolve this.
    Thanks in advance,
    RV

    Thanks.Here is the sample XML. Fields that refer to are as follows:
    Children: DependentDD1, DependentDD2, DependentDD3
    Name: DependentFF1, DependentFF2, DependentFF3
    Grandchildren: GrandchildDD1, GrandchildDD2, GrandchildDD3
    Name: GrandchildFF1, GrandchildFF2, GrandchildFF3
    <?xml version="1.0" encoding="UTF-8" ?>
    - <ListofIO>
    - <ListOfBipCustomerProfileReport>
    - <Contact>
    <FirstName>ROSCOE</FirstName>
    <LastName>CLOUGH</LastName>
    <LeadContactType />
    <PartyTypeCode>Person</PartyTypeCode>
    <PartyUId>XXXXXXXXX</PartyUId>
    <PersonUId>XXXXXXXXX</PersonUId>
    <PrivacyCode>Opt-Out: All Parties</PrivacyCode>
    <RelationtoHousehold />
    <SocialSecurityNumber>XXXXXXXXX</SocialSecurityNumber>
    <UserType>Prospect</UserType>
    - <ListOfA-FmrCustomerProfile>
    - <A-FmrCustomerProfile>
    <DependentDD1>Son</DependentDD1>
    <DependentDD2>Daughter</DependentDD2>
    <DependentDD3 />
    <DependentFF1>John</DependentFF1>
    <DependentFF2>Laura</DependentFF2>
    <DependentFF3 />
    <GrandchildDD1>Daughter</GrandchildDD1>
    <GrandchildDD2>Son</GrandchildDD2>
    <GrandchildDD3 />
    <GrandchildFF1>Smith</GrandchildFF1>
    <GrandchildFF2>Kevin</GrandchildFF2>
    <GrandchildFF3 />
    </A-FmrCustomerProfile>
    </ListOfA-FmrCustomerProfile>
    </Contact>
    <Login>A482003</Login>
    </ListOfBipCustomerProfileReport>
    </ListofIO>

  • How do I create a new Work Center for the transaction launcher and links

    Hi
    The requirement here is for me to find out if I can create a new Work Center that will contain up to 6 assignment blocks and each block having either links to websites and BW reports, or triggers to R/3 applications via the transaction launcher.
    Can I do this purely through customising or do I need to create a new view using BSPs? If I can do it through customising please could I have a few pointers to what component I would need to use/copy?
    Regards
    Declan

    Hi Robert,
    Thanks again for taking the time to reply.
    Just so I understand, if I want to show a work center I need to link it to a component / view? I think this was the original query - do I need a developer to create the view that contains the 6 blocks with their links to reports, transactions and websites? I think when I talk about blocks I mean 1 viewset containing 6 views. There is no SAP standard view that would suit my requirements is there? Even if the work center had 8 views, I can always hide the two views in configuration.
    After the developer has created the view, I then reference that component in the target Id in the define logical links section of my work center.
    If my understanding is right, then it follows that it is not possible to create a user specific work center without some development.
    Is this correct?
    Cheers
    Declan

  • How to Print File Path and File Name at the bottom of the Report?

    Hi guys,
    I have situation where i have to display my file path where i save my file. For example: U:\Reports\Monthly_Reports\Compay_xyz.jsp
    also, after the file path line if its possible i would like to display the date where the last modification done on the file.
    I read one of the post and some one suggested that use srw.get_report_name() but since i am a new to Reporting i am not sure how to use it.
    Can anyone describe me little bit in detail please?
    Thank You.

    Hi,
    Your logic seems to be fine and you should put it in the additional plsql code section "After displaying the page". But you may have to check you syntax by compiling it. You cannot use "LINEFEED". It should be '<br>'. This is the line break in html. Please check your type declaration. Also some ';' is missing after some statements.
    Hope that helps.
    Thanks,
    Sharmila

  • How to print text in English & chinese lang in the same window in smartform

    Hi All,
    My requirement is in the Smartform for few windows i need the text in the English Language as well as corresponding Text in chinese Language.
    For Eg                               Buyer:                         
                                             需方:                         
                                            Address                         
                                            地址:                         
                                            Contact:                         
                                            联系人:                         
                                           Tel:                                     Fax:          
                                           电话:                                                  传真          
                   I need only the corresponding  Labels to be converted to  the chinese language.  Please let me know how this can be done.
    Thank you.

    Hi Vasudha,
    You maintain the English & chinese text in different standard text using SO10 in different languages.
    Then include these texts in your smart forms.
    The  process to include these texts :
    Right click on the node=>create=>text=>choose the type as Include text.
    Text Name         <The standard text created in SO10>
    Text Object       TEXT
    Text ID           ST
    Language          <Language>
    Regards
    DKS

  • How can I spend my 0,27 cents in the app store(because i can't change my country)

    Hello!
    Help me, please. I can't change my country, because i have a little money on my account.
    I don't know how to spend my 27 cents...

    Click here and request assistance.
    (62089)

  • Double Clicking the Job in Control Center hangs the Mapping

    i have deployed a mapping.
    When i run the mapping the mapping fails
    When i double click the job for the particular mapping in the control center,The system hangs.
    Please let me know the reason for the same and how to resolve it.

    Thanks for the reply David. I'm using OWB 10.2.0.4. Is this a known bug? I don't mind splitting into 2 mappings. My only concern is that ~60% of the data processing are overlapping. I'm using MOLAP. Is there a way to share staged table data on 2 different mappings?

  • How to print Arabic text along with the English in smartform ( ECC6 version

    Hi All,
    our is ECC6 version, Non unicode, ABAP stack ( not dual stack )
    is it possible to print in Arabic language in the above version ?
    if yes, then please let me know how to print Arabic text and English text in the same smartfrom.
    i tried in the following procedures :
    1) i created standard text (SO10) in arabic language.
    i called in the smartform ( include text - i )
    langage AR
    but system throws error message saying, required language is not installed.
    2) if i use READ_TEXT function module.
    text getting printed in diff format but not in arabic.
    waiting for your replies..

    ECC6 and Non-Unicode? I think you'll need multiple code pages, I doubt there's a mixed Arabic/Latin1 available. And I don't think SAP supports new MDMP systems any more. If you need to support multiple languages you really need to go Unicode. It's probably easier to do the Unicode conversion than to try to support multiple code pages and you have to make the switch eventually.

  • How to resize the components in a JFrame when the JFrame Resizes?

    Hi all,
    i have some problems with my app. I have set the JFrame resizable and that works fine for the JFrame but not for the components in the JFrame.
    So my question is how can i set the components in a JFrame to resize automatically when the JFrame resizes?
    Here are the important things from my code,...if you need more, just let me know, its my first post in a forum .
    Its a JFrame with a JTabbedPane and on the Tabs are Panels with buttons and Tables.
    Thank you in advance!
    public class MainMonitor extends JFrame {
    public MainMonitor() {
              super();
              initialize();
              setVisible(true);
         private void initialize() {
              this.setSize(1145, 785);
              this.setIconImage(Toolkit.getDefaultToolkit().getImage("Images/c.gif"));
              this.setContentPane(getJContentPane());
              this.setTitle("Company Manager");
              this.setResizable(true);
              this.setLocationRelativeTo(null);
         private JPanel getJContentPane() {
              if (jContentPane == null) {
                   jContentPane = new JPanel();
                   jContentPane.setLayout(null);
                   jContentPane.setOpaque(true);
                   jContentPane.add(getJTabbedPane(), null);
                   jContentPane.add(getJPanel11(), null);
              return jContentPane;
         private JTabbedPane getJTabbedPane() {
              if (jTabbedPane == null) {
                   jTabbedPane = new JTabbedPane();
                   jTabbedPane.setLocation(new Point(6, 69));
                   jTabbedPane.setSize(new Dimension(1120, 684));
                   jTabbedPane.addTab("P", null, getJPanel(), null);
                   jTabbedPane.addTab("K", null, getJPanel1(), null);
                   jTabbedPane.addTab("B", null, getJPanel2(), null);
              return jTabbedPane;
         

    Giasaste wrote:
    Thanks a lot, i didnt knew that the Layout Manager is a must.It's not a must, but it is the way to allow your app to be resized nicely and makes it much easier to maintain and enhance your program. Imagine creating a complex gui then later decide that you want another radiobutton and to remove a jlabel / jtextfield pair. with layout managers a chore becomes easy.

  • How to fullscreen the JFrame?

    hi java_nuts,
    can anyone of u give me the trend(code) of full-screening the JFrame.
    i remember someone using the code: getToolkit() something. I forgot the rest line.
    thanks in advance
    -- sushil

    How about searching the forum using "fullscreen" as the keyword?

Maybe you are looking for

  • Creating a web service from existing EJB.  HELP!!!

    I have an existing EJB deployed to WL which I want to call as a web service. I do not want to deploy everything in an EAR - I want to use the existing EJB. Basically I just created a new web module and put my web-services.xml (and web.xml) in WEB-INF

  • Error message when Sync from itunes.

    I have 2 TVs, both have the latest update, iTunes 8, using AE for WIFI and both streaming. Both units have been working great for over a year now. One of the unit is now freezing up after about 1hr of use... I get this error message from iTunes when

  • JDBC Adapter message order

    Hello experts, I want to ask one question. If I use JDBC adapter for processing outgoing message (receiver JDBC adapter) - Is processing of message guaranteed in order how I received it on sender side or processing order can change and I will insert

  • DVD Player app version 4.6 OS X 10.7.5. Won't run. Says incompatible with OS.

    How do I find what should be the version of DVD Player .app that is compatible with 10.7.5 My version is 4.6 with a 'last modified' of 3/03/13. I am fully up to date with Apple Software Update. Where can I download a compatible version of DVD player

  • Safari 5.1 won't load webpages after install

    safari 5.1 wont load any webpages on my pc running vista. I have uninstalled and reinstalled and still nothing. all the other browswers work just fine.  any ideas or help?