how can i make the border line to the position shown in the attachment

package proj;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.print.PrinterJob;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.print.Book;
import java.awt.print.PageFormat;
import java.awt.print.Printable;

public class j extends javax.swing.JFrame {
    public  int st,i,k1,k2;PrinterJob printJob = PrinterJob.getPrinterJob();
    String str[]=new String[20];

    public j() {
        initComponents();
    }
   public class IntroPage implements Printable {
        
        @Override
    public int print(Graphics g, PageFormat pageFormat, int page) {
            
       k1=page;
       if(k2==k1)
       {
           k2++;
       }
  
     Graphics2D g2d = (Graphics2D) g;

      //--- Translate the origin to 0,0 for the top left corner
      g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());

      //--- Set the default drawing color to black
      g2d.setPaint(Color.black);

      //--- Draw a border arround the page
      Rectangle2D.Double border = new Rectangle2D.Double(0, 1, 451.224, 696);
      g2d.draw(border);
      System.out.println("Width:"+pageFormat.getImageableWidth());
      System.out.println("Height:"+pageFormat.getImageableHeight());
      //--- Print the title

      String titleText = "Printing in Java Part "+k2+", Example 4";

      g2d.drawString(titleText,200 ,200 );
      return (PAGE_EXISTS);
    }
  }
     
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jTextField1 = new javax.swing.JTextField();
        print = new javax.swing.JButton();

        jTextField1.setText("jTextField1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        print.setText("print");
        print.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                printActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(86, 86, 86)
                .addComponent(print)
                .addContainerGap(259, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(57, 57, 57)
                .addComponent(print)
                .addContainerGap(220, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    private void printActionPerformed(java.awt.event.ActionEvent evt) {                                      
        // TODO add your handling code here:
        Book book = new Book();

        PageFormat documentPageFormat = new PageFormat();
        documentPageFormat.setOrientation(PageFormat.PORTRAIT);

        book.append(new IntroPage(), printJob.defaultPage());  
               
        printJob.setPageable(book);
      
    //--- Show the print dialog box. If the user click the
    //--- print button we then proceed to print else we cancel
    //--- the process.
       if (printJob.printDialog()) {
       try {
        printJob.print();
      } catch (Exception e) {      }
    }
    }                                     

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new j().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JTextField jTextField1;
    private javax.swing.JButton print;
    // End of variables declaration                   
}

Recommended Answers

All 13 Replies

Where is the code that produces the image you show?
The posted code when executed: shows a window with a single button on it.

Where is the code that produces the image you show?
The posted code when executed: shows a window with a single button on it.

ys that button is for print, which produces the above image

the colored text and lines is not there when executed

Have you tried changing this line?
Rectangle2D.Double border = new Rectangle2D.Double(0, 1, 451.224, 696);

ys when i changed the value like this

Rectangle2D.Double border = new Rectangle2D.Double(-4, -4, 200, 500);

what i gets is shown in the image

You are able to change the location of the border.
Now keep trying until you get it where you want it.

but sir , the top,right,bottom line disappears for the value 0, 0, 470, 697

Rectangle2D.Double border = new Rectangle2D.Double(0, 0, 470, 697);

how can we make that line visible

Keep trying.

Keep trying.

how can we make that lines(that are not visible)to be visible.........

Where are the invisible lines? Do you mean lines that are drawn outside of the graphics content.

ys........

Then move them back into the visible area.

commented: nice thread +8

Then move them back into the visible area.

sir actually what i want is that i want to expand the expand the border line that which you can see in the print.jpg image , but when i expand the lines disappears since it is out of graphics content..........so what will i do to expand the graphics content space so that i can expand the border line

Have you looked at the classes and methods involved with printing. For example:
public Paper()
Creates a letter sized piece of paper with one inch margins.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.