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() {
   public class IntroPage implements Printable {
    public int print(Graphics g, PageFormat pageFormat, int page) {
     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

      //--- Draw a border arround the page
      Rectangle2D.Double border = new Rectangle2D.Double(0, 1, 451.224, 696);
      //--- Print the title

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

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

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



        print.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
                .addGap(86, 86, 86)
                .addContainerGap(259, Short.MAX_VALUE))
                .addGap(57, 57, 57)
                .addContainerGap(220, Short.MAX_VALUE))

    }// </editor-fold>                        

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

        PageFormat documentPageFormat = new PageFormat();

        book.append(new IntroPage(), printJob.defaultPage());  
    //--- 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 {
      } catch (Exception e) {      }

     * @param args the command line arguments
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            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                   
Attachments print.jpg 47.79 KB

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

Edited 5 Years Ago by Jessurider: n/a

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

Attachments print2.jpg 44.82 KB

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

Edited 5 Years Ago by Jessurider: n/a

Attachments print3.jpg 44.76 KB

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

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 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.

This article has been dead for over six months. Start a new discussion instead.